android seekbar使用

用到了seekbar, so 上网找了下小demo,这位仁兄总结的很好,现转贴在这里。

 

原文地址:http://bashenmail.iteye.com/blog/603649

 

SeekBar配置文件:

 

Xml代码   收藏代码
  1. < SeekBar    
  2.          android:id = "@+id/player_seekbar"   
  3.          android:layout_width = "245px"   
  4.          android:layout_height = "25px"   
  5.          android:progressDrawable = "@drawable/seekbar_style"   
  6.          android:thumb = "@drawable/thumb"   
  7.          android:paddingLeft = "16px"   
  8.          android:paddingRight = "15px"   
  9.          android:paddingTop = "5px"   
  10.          android:paddingBottom = "5px"   
  11.          android:progress = "0"   
  12.          android:max = "0"   
  13.          android:secondaryProgress = "0"   
  14.          />     

 android:progressDrawable="@drawable/seekbar_style"背景条

seekbar_style配置如下:

Xml代码   收藏代码
  1. <? xml   version = "1.0"   encoding = "UTF-8" ?>   
  2.   
  3. < layer-list   xmlns:android = "http://schemas.android.com/apk/res/android" >   
  4.   
  5.      < item   android:id = "@android:id/background" >   
  6.          < shape >   
  7.              < corners   android:radius = "5dip"   />   
  8.              < gradient   
  9.                      android:startColor = "#ff9d9e9d"   
  10.                      android:centerColor = "#ff5a5d5a"   
  11.                      android:centerY = "0.75"   
  12.                      android:endColor = "#ff747674"   
  13.                      android:angle = "270"   
  14.              />   
  15.          </ shape >   
  16.      </ item >   
  17.   
  18.      < item   android:id = "@android:id/secondaryProgress" >   
  19.          < clip >   
  20.              < shape >   
  21.                  < corners   android:radius = "5dip"   />   
  22.                  < gradient   
  23.                          android:startColor = "#80ffd300"   
  24.                          android:centerColor = "#80ffb600"   
  25.                          android:centerY = "0.75"   
  26.                          android:endColor = "#a0ffcb00"   
  27.                          android:angle = "270"   
  28.                  />   
  29.              </ shape >   
  30.          </ clip >   
  31.      </ item >   
  32.   
  33.      < item   android:id = "@android:id/progress" >   
  34.          < clip >   
  35.              < shape >   
  36.                  < corners   android:radius = "5dip"   />   
  37.                  < gradient   
  38.                          android:startColor = "#ff0099CC"   
  39.                          android:centerColor = "#ff3399CC"   
  40.                          android:centerY = "0.75"   
  41.                          android:endColor = "#ff6699CC"   
  42.                          android:angle = "270"   
  43.                  />   
  44.              </ shape >   
  45.          </ clip >   
  46.      </ item >   
  47.   
  48.  </ layer-list >   

 或者:用图片如下:

 

Xml代码   收藏代码
  1. <? xml   version = "1.0"   encoding = "utf-8" ?>   
  2. < layer-list   xmlns:android = "http://schemas.android.com/apk/res/android" >   
  3.       
  4.     < item   android:id = "@android:id/background"    
  5.           android:drawable = "@drawable/progress_bg"   />   
  6.        
  7.     < item   android:id = "@android:id/secondaryProgress"   
  8.           android:drawable = "@drawable/second_progress" >   
  9.     </ item >      
  10.       
  11.     < item   android:id = "@android:id/progress"   
  12.           android:drawable = "@drawable/first_progress" >   
  13.           
  14.     </ item >    
  15. </ layer-list >   

 方形

Xml代码   收藏代码
  1. < layer-list   xmlns:android = "http://schemas.android.com/apk/res/android" >    
  2.   
  3.   
  4.     < item   android:id = "@android:id/background"    
  5.     android:drawable = "@drawable/progress_bg"   />    
  6.   
  7.   
  8.     < item   android:id = "@android:id/secondaryProgress" >    
  9.      < clip   android:drawable = "@drawable/second_progress"   />    
  10.     </ item >    
  11.   
  12.   
  13.     < item   android:id = "@android:id/progress" >    
  14.          < clip   android:drawable = "@drawable/first_progress"   />    
  15.     </ item >    
  16.   
  17.   
  18. </ layer-list >   

 

 

 

 android:thumb="@drawable/thumb"就是那个会动的球

  配置如下:

 

Xml代码   收藏代码
  1. <? xml   version = "1.0"   encoding = "UTF-8" ?>   
  2. < selector   xmlns:android = "http://schemas.android.com/apk/res/android" >        
  3.       
  4.     <!-- 按下状态-->   
  5.     < item    
  6.         android:state_focused = "true"    
  7.         android:state_pressed = "true"    
  8.         android:drawable = "@drawable/thumb_pressed"   />        
  9.     <!-- 普通无焦点状态 -->   
  10.     < item    
  11.         android:state_focused = "false"    
  12.         android:state_pressed = "false"   
  13.         android:drawable = "@drawable/thumb_normal"   />              
  14.     <!-- 有焦点状态-->   
  15.     < item    
  16.         android:state_focused = "true"    
  17.         android:state_pressed = "false"              
  18.         android:drawable = "@drawable/thumb_focused"   />         
  19.     <!-- 有焦点 -->   
  20.     < item    
  21.         android:state_focused = "true"              
  22.         android:drawable = "@drawable/thumb_focused"   />     
  23. </ selector >   

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值