笔记——Android自定义seekbar中,滑块显示不全解决办法

自定义seekBar的时候发现,圆形滑块总有一部分被覆盖,设置什么padding之类的病不起作用,查找资料发现

android:thumbOffset="0dp"

在布局文件中加上thumbOffset属性可以解决,thumbOffset属性表示滑块距离左侧的间距。


下面附上自定义SeekBar

<SeekBar
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:maxHeight="4dp"
            android:minHeight="4dp"
            android:paddingLeft="16dp"
            android:paddingRight="16dp"
            android:thumbOffset="0dp"
            android:progressDrawable="@drawable/bg_seek_bar_drawable"
            android:thumb="@drawable/ic_seek_bar" />

其中bg_seek_bar_drawable文件设置seekbar进度条的样式,文件如下:

<?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>
            <solid android:color="#8e8e8e" />
        </shape>
    </item>
    <item android:id="@android:id/secondaryProgress">
        <clip>
            <shape>
                <solid android:color="#008e8e8e" />
            </shape>
        </clip>
    </item>
    <item android:id="@+android:id/progress">
        <clip>
            <shape>
                <solid android:color="#ffa74b" />
            </shape>
        </clip>
    </item>
</layer-list>
ic_seek_bar为一张滑块的图片,效果如下图


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值