Android-如何更改默认的SeekBar厚度? [英] Android - How to change default SeekBar thickness?

查看:56
本文介绍了Android-如何更改默认的SeekBar厚度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个SeekBar:

I have this SeekBar:

        <SeekBar
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="26dp"
        android:id="@+id/seekbar"
        android:visibility="gone"
        android:maxHeight="3dp"/>

我尝试使用maxHeight更改此SeekBar的厚度.但是什么都没有改变.看起来像这样:

I have tried to change this SeekBar thickness using maxHeight. But nothing changed. It looks like this:

我想将此SeekBar的厚度更改为3dp,并使其如下所示:

I want to change this SeekBar's thickness to 3dp and make look like this:

所以我的问题是可以以某种方式更改SeekBar的厚度吗?如果是,怎么办?

So my question is it possible to change SeekBar thickness somehow? If yes, how?

推荐答案

您必须更改 SeekBar progressDrawable thumb 来进行调整厚度:

You have to change progressDrawable and thumb of SeekBar to adjust it's thickness :

<SeekBar
    android:id="@+id/seekBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/indSeekBar"
    android:layout_marginTop="48dp"
    android:progressDrawable="@drawable/seek_bar"
    android:thumb="@drawable/seek_thumb"
    />

添加可绘制文件夹 seek_bar.xml :

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/background">
        <shape
            android:shape="line">
            <stroke
                android:color="@color/seek_bar_background"
                android:width="@dimen/seek_bar_thickness"/>
        </shape>
    </item>
    <item android:id="@android:id/secondaryProgress">
        <clip>
            <shape
                android:shape="line">
                <stroke
                    android:color="@color/seek_bar_secondary_progress"
                    android:width="@dimen/seek_bar_thickness"/>
            </shape>
        </clip>
    </item>

    <item android:id="@android:id/progress">
        <clip>
            <shape
                android:shape="line">
                <stroke
                    android:color="@color/seek_bar_progress"
                    android:width="@dimen/seek_bar_thickness"/>
            </shape>
        </clip>
    </item>

</layer-list>

seek_thumb.xml :

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <size
        android:height="@dimen/seek_bar_thumb_size"
        android:width="@dimen/seek_bar_thumb_size"
        />
    <solid android:color="@color/seek_bar_progress"/>
</shape>

添加到尺寸资源(更改此尺寸以调整厚度):

Add to dimension resources (change this to adjust thickness) :

<dimen name="seek_bar_thickness">4dp</dimen>
<dimen name="seek_bar_thumb_size">20dp</dimen>

添加颜色资源:

<color name="seek_bar_background">#ababab</color>
<color name="seek_bar_progress">#ffb600</color>
<color name="seek_bar_secondary_progress">#3399CC</color>

这篇关于Android-如何更改默认的SeekBar厚度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆