Drawable 資源圖:bitmap shape layer stateList
bitmap :
<?xml version="1.0" encoding="utf-8"?>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="bitmap——id" 指定圖檔
android:antialias="true | false" 圖檔是否開啟抗鋸齒功能
android:dither="true | false" 是否開啟抖動功能:可以讓高品質圖檔在低品質螢幕顯示的好
android:filter="true | false" 過濾效果,圖檔被拉伸或壓縮時,可以保持較好的效果
android:gravity="top | bottom | left ....." 圖檔小與容器,可以對圖檔進行定位
android:mipMap="true | false"
android:tileMode="disabled | clamp | repeat | mirror " 平鋪模式
shape: 用顔色來建構圖形。有純色 有漸變
<? xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http//schemas.android.com/apk/res/android"
android:shape="rectangle | oval | line | ring"> 矩形 橢圓 橫線 圓環
<corners 設定四個角的角度
android:radius="integer" 四個角設定相同角度
android:topLeftRadius="integer" 左上角度
android:topRightRadius="integer"
android:bottomLeftRadius="integer"
android:bottomRightRadius="integer" />
<gradient 與solid标簽互相排斥,顔色漸變填充,
android:angle="integer" 漸變的角度,預設0,其之必須為45的倍數,0從做到右 90從下到上
android:centerX="integer" 漸變的中心點的橫坐标
android:centerY="integer"
android:centerColor="color" 漸變的中間色
android:endColot="color" 漸變結束的顔色
android:gradientRadius="integer" 漸變半徑, 僅當android:type="radial"有效
android:startColor="color" 漸變開始的顔色
android:type="linear | radial | sweep" 漸變類型。線性漸變 徑向漸變 描線漸變
android:useLevel="true | false" /> 一般為false 當statelistDrawable時有用
<padding 空白,表示包含它的view的空白
android:left|top|right|bottom="integer"/>
<size
android:width="integer"
android:height="integer"/>
<solid 表示顔色純色填充,
andorid:color="color"/>
<stroke shape描邊
android:width="integer" 描邊寬度
android:color="color" 描邊顔色
android:dashWidth="integer" 組成虛線的線段的寬度
android:dashGap="integer"/> 組成虛線的線段之間的間隔,
</shape>
在shape類型中ring圓環有5個特殊的屬性。
android:innerRadius 圓環内半徑 與innerRadiusRatio同時存在,
android:innerRadiusRatio 内半徑占整個drawable寬度的比例,預設為9, 若為n 那麼内半徑=寬度/n
android:thickness 圓環厚度,就是圓外半徑減去内半徑,和thicknessRatio同時存在,
android:thicknessRadio 厚度占整個圓環寬度的比,預設為3, 若為n 那麼厚度=寬度/n
android:useLevel 一般使用為false, 一般沒有效果,但在levelListDrawable中來使用好。
Layer :對應的标簽<layer_list>一種層次疊加的drawable集合
<? xml version="1.0" encoding="utf-8">
<layer-list
xmlns:....>
<item 多個item,每個item表示一個drawable
android:drawable=" "
android:id=" "
android:top|right|bottom|left ="dimension"
</layer-list>
stateListDrawable : <selector> 可以根據點選切換view背景
<?xml version="1.0" encoding="utf-8">
<selector
xmlns:android=" "
android:constantSize="true | false" 固有大小是否不随着其狀态而改變。
android:dither="true | false" 是否開啟抖動效果
android:variablePadding="true | false "> padding是否随着其狀态改變而改變。
<item
android:drawable=" " 加載的圖檔
android:state_pressed="true | false" 表示按下狀态
android:state_focused="true | false" 以獲得焦點
android:state_hovered="true | false"
android:state_selected="true | false" 表示使用者選擇了view
android:state_checked="true | false" 表示使用者選中,一般使用checkbox
android:state_enabled="true | false" 表示view目前處于可用狀态
android:state_activated="true | false"
android_state_window_focused="true | false" />
</selector>
還有: insetDrawable TransitionDrawable ScaleDrawable clipDrawable
(2)在ListView的item界面中添加如下屬性代碼
[html] view plain copy
android:background=”@drawable/mylist_view”
(3)利用JAVA代碼直接編寫
[java] view plain copy
Drawable drawable = getResources().getDrawable(R.drawable.mylist_view);
listView.setSelector(drawable);