2020-09-07

SeekBar的简单使用

XML:添加控件

<SeekBar
            android:id="@+id/seekbar"
            android:layout_width="match_parent"
            android:layout_height="20dp"
            android:max="1000"
            android:minHeight="20dp"
            android:maxHeight="20dp"
            android:paddingStart="0dp"
            android:paddingEnd="0dp"
            android:splitTrack="false"
            android:progressDrawable="@drawable/seekbar_style"
            android:thumb="@drawable/select_seekbar" />
android:max="1000" 设置seekbar的最大值,需要自己按控制seekbar进度的比例
设置SeekBar的最小高度,和最大高度;当自定义progressDrawable无法居中显示时,只需要设置这两个参数为同一值,就可以解决问题
android:minHeight="20dp"
android:maxHeight="20dp"

设置SeekBar的开始、结束的Padding,默认SeekBar的Padding不为0

android:paddingStart="0dp"
android:paddingEnd="0dp"
当设置SeekBar的ProgressDrawable与进度条出现空隙时,需要将android:splitTrack设置为false

android:splitTrack="false"
简单自定义设置SeekBar的progressDrawable
android:progressDrawable="@drawable/seekbar_style
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    //根据id设置资源类型(seekBar背景)
    <item android:id="@android:id/background">
        <shape android:shape="line">
            <stroke android:color="@color/color_808080"
                android:width="0.5dp" />
        </shape>
    </item>

    //已加载的进度drawable
    <item android:id="@android:id/progress">
        <clip>
            <shape android:shape="line">
                <stroke android:color="#ffffffff"
                    android:width="1dp" />
            </shape>
        </clip>

    </item>

    //还可以设置二级progress,一般作为缓冲进度使用
    //android:id="@android:id/secondaryProgress"
    


</layer-list>
设置SeekBar的thumb可以根据不用的状态设置多种drawable
android:thumb="@drawable/select_seekbar"
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    
    <item android:state_focused="false"
        android:state_pressed="false"
        android:drawable="@drawable/drawable_no_focused"/>

    <item
        android:state_pressed="true"
        android:drawable="@drawable/drawable_thnumb"/>

    <item
        android:state_focused="true"
        android:state_pressed="true"
        android:drawable="@drawable/drawable_thnumb"/>

</selector>

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值