Android 背后的XML设置

一  使用XML定义背景

 属性备注
shape 矩形(rectangle)、椭圆形(oval)、线性形状 (line)、环形(ring)shape=ring
   innerRadius 尺寸,内环的半径
   innerRadiusRatio 浮点型,以环的宽度比率来表示内环的半径
   thickness 尺寸,环的厚度
   thicknessRatio 浮点型,以环的宽度比率来表示环的厚度
solid color内部填充
gradient startColor
 endColor
 centerColor
 angle
 type
 gradientRadius
 centerX
 centerY
渐变色
angle      渐变角度(PS:当angle=0时,渐变色是从左向右。 然后逆时针方向转,当angle=90时为从下往上。angle必须为45的整数倍)
type   渐变类型
         linear 线性渐变默认
         radial 以开始色为中心放射
         sweep
gradientRadius 整型 渐变色半径.当 android:type="radial" 时才使用
centerX     渐变中心X点坐标的相对位置
centerY     渐变中心Y点坐标的相对位置
stroke width
 color
 dashWidth
 dashGap 
dashWidth 整型 表示描边的样式是虚线的宽度, 值为0时,表示为实线
dashGap   整型 表示描边为虚线时,虚线之间的间隔 即“ - - - - ”
corners radius
 topLeftRadius
 topRightRadius
 bottomLeftRadius
 bottomRightRadius
圆角
padding left
 top
 right
 bottom
内边距,即内容与边的距离
size width
 height
 
   

二  selector (选择器)的设置

属性备注
state_selected选中
state_focused获得焦点
state_pressed点击
state_enabled设置是否响应事件
focusableandroid:focusable="true" android:background="@drawable/button_color"
  


使用实例:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 默认时的背景图片-->  
  <item android:drawable="@drawable/pic1" />    
<!-- 没有焦点时的背景图片 -->  
  <item android:state_window_focused="false"   android:drawable="@drawable/pic1" />   
<!-- 非触摸模式下获得焦点并单击时的背景图片 -->  
  <item android:state_focused="true" android:state_pressed="true"   android:drawable= "@drawable/pic2" />
<!-- 触摸模式下单击时的背景图片--> 
  <item android:state_focused="false" android:state_pressed="true"   android:drawable="@drawable/pic3" /> 
<!--选中时的图片背景--> 
  <item android:state_selected="true"   android:drawable="@drawable/pic4" />  
<!--获得焦点时的图片背景--> 
  <item android:state_focused="true"   android:drawable="@drawable/pic5" />   
</selector>

引用方法

1. background="@drawable/xxx"

2. Drawable drawable = getResources().getDrawable(R.drawable.xxx);  
ListView.setSelector(drawable);

出现列表有时候为黑的情况,需要加上:android:cacheColorHint="@android:color/transparent"使其透明。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值