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);