android seekbar使用
16lz
2021-01-25
用到了seekbar, so 上网找了下小demo,这位仁兄总结的很好,现转贴在这里。
原文地址:http://bashenmail.iteye.com/blog/603649
SeekBar配置文件:
Xml代码- < SeekBar
- android:id = "@+id/player_seekbar"
- android:layout_width = "245px"
- android:layout_height = "25px"
- android:progressDrawable = "@drawable/seekbar_style"
- android:thumb = "@drawable/thumb"
- android:paddingLeft = "16px"
- android:paddingRight = "15px"
- android:paddingTop = "5px"
- android:paddingBottom = "5px"
- android:progress = "0"
- android:max = "0"
- android:secondaryProgress = "0"
- />
android:progressDrawable="@drawable/seekbar_style"背景条
seekbar_style配置如下:
Xml代码- <? xml version = "1.0" encoding = "UTF-8" ?>
- < layer-list xmlns:android = "http://schemas.android.com/apk/res/android" >
- < item android:id = "@android:id/background" >
- < shape >
- < corners android:radius = "5dip" />
- < gradient
- android:startColor = "#ff9d9e9d"
- android:centerColor = "#ff5a5d5a"
- android:centerY = "0.75"
- android:endColor = "#ff747674"
- android:angle = "270"
- />
- </ shape >
- </ item >
- < item android:id = "@android:id/secondaryProgress" >
- < clip >
- < shape >
- < corners android:radius = "5dip" />
- < gradient
- android:startColor = "#80ffd300"
- android:centerColor = "#80ffb600"
- android:centerY = "0.75"
- android:endColor = "#a0ffcb00"
- android:angle = "270"
- />
- </ shape >
- </ clip >
- </ item >
- < item android:id = "@android:id/progress" >
- < clip >
- < shape >
- < corners android:radius = "5dip" />
- < gradient
- android:startColor = "#ff0099CC"
- android:centerColor = "#ff3399CC"
- android:centerY = "0.75"
- android:endColor = "#ff6699CC"
- android:angle = "270"
- />
- </ shape >
- </ clip >
- </ item >
- </ layer-list >
或者:用图片如下:
Xml代码- <? xml version = "1.0" encoding = "utf-8" ?>
- < layer-list xmlns:android = "http://schemas.android.com/apk/res/android" >
- < item android:id = "@android:id/background"
- android:drawable = "@drawable/progress_bg" />
- < item android:id = "@android:id/secondaryProgress"
- android:drawable = "@drawable/second_progress" >
- </ item >
- < item android:id = "@android:id/progress"
- android:drawable = "@drawable/first_progress" >
- </ item >
- </ layer-list >
方形
Xml代码- < layer-list xmlns:android = "http://schemas.android.com/apk/res/android" >
- < item android:id = "@android:id/background"
- android:drawable = "@drawable/progress_bg" />
- < item android:id = "@android:id/secondaryProgress" >
- < clip android:drawable = "@drawable/second_progress" />
- </ item >
- < item android:id = "@android:id/progress" >
- < clip android:drawable = "@drawable/first_progress" />
- </ item >
- </ layer-list >
android:thumb="@drawable/thumb"就是那个会动的球
配置如下:
Xml代码- <? xml version = "1.0" encoding = "UTF-8" ?>
- < selector xmlns:android = "http://schemas.android.com/apk/res/android" >
- <!--按下状态-->
- < item
- android:state_focused = "true"
- android:state_pressed = "true"
- android:drawable = "@drawable/thumb_pressed" />
- <!--普通无焦点状态-->
- < item
- android:state_focused = "false"
- android:state_pressed = "false"
- android:drawable = "@drawable/thumb_normal" />
- <!--有焦点状态-->
- < item
- android:state_focused = "true"
- android:state_pressed = "false"
- android:drawable = "@drawable/thumb_focused" />
- <!--有焦点-->
- < item
- android:state_focused = "true"
- android:drawable = "@drawable/thumb_focused" />
- </ selector >
更多相关文章
- 没有一行代码,「2020 新冠肺炎记忆」这个项目却登上了 GitHub 中
- PopupWindow位置
- Android(安卓)摄像头自动对焦的几点注意
- Android(安卓)Studio 设置内存大小及原理
- AlertDialog使用自定义的布局
- java.io.IOException:Can't read [F:\..\android-support-v4.ja
- Android应用开发之(你必须知道的android selector下的属性值)
- android之解析包时出现错误(二)
- android之点击回退键俩次退出程序