自定义drawable(shape)

自定义drawable(shape)


android中可以通过shape对drawable进行自定义。

 

[xhtml]  view plain copy
  1. <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">  
  2.     <solid android:color="#f033ff22"/>  
  3.     <stroke android:width="2dp" android:color="#ff1111" android:dashWidth="2dp"  
  4.      android:dashGap="0dp" />  
  5.     <padding android:left="10dp" android:top="10dp"  
  6.             android:right="10dp" android:bottom="10dp" />  
  7.     <corners android:radius="6dp" />  
  8. </shape>   

solid中定义的颜色值需要包含alpha值,

stroke可以定义边框的颜色,width为边框的宽度,dashWidth为画笔的宽度,dashGap为画笔的间距

(dashGap为0,则边框为实心的边线)

corners定义四角圆弧的半径。

 

TIP:

对于使用selector定义不同的状态也可以使用shape替代drawable的属性。

 

[xhtml]  view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>    
  2. <selector xmlns:android="http://schemas.android.com/apk/res/android">     
  3.     <item android:state_focused="false"     
  4.         android:drawable="@drawable/gallery_selected_unfocused" />     
  5.     <item android:state_focused="true"     
  6.         android:drawable="@drawable/gallery_selected_focused" />     
  7.     <item android:state_pressed="true"     
  8.         android:drawable="@drawable/gallery_unselected_focused" />     
  9.    <item android:state_selected="true"     
  10.         android:drawable="@drawable/gallery_unselected_focused" />     
  11. </selector>  

 

--->>>

[xhtml]  view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>    
  2. <selector xmlns:android="http://schemas.android.com/apk/res/android">     
  3.     <item android:state_focused="false" >  
  4.         <shape>  
  5.             <solid ...>  
  6.             </solid>  
  7.         </shape>  
  8.     </item>  
  9.     <item android:state_focused="true"  >  
  10.         <shape>  
  11.             <solid ...>  
  12.             </solid>  
  13.         </shape>  
  14.     </item>  
  15.     <item android:state_pressed="true" >  
  16.         <shape>  
  17.             <solid ...>  
  18.             </solid>  
  19.         </shape>  
  20.     </item>   
  21. </selector>  

文章转自:http://blog.csdn.net/hknock/article/details/6313722

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值