Seekbar中的可变厚度

时间:2018-12-14 06:41:51

标签: android android-layout android-seekbar

我想要搜寻杆厚度变量。搜寻棒的进度部分应比其余部分更厚。这是我想要的:enter image description here

你能建议我吗?抱歉,图像质量:P

1 个答案:

答案 0 :(得分:1)

尝试一下

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <SeekBar
        android:layout_marginTop="10dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:progressDrawable="@drawable/test"
        android:thumb="@drawable/ic_send" />

</LinearLayout>
  

android:progressDrawable =“ @ drawable / test”

<?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:gravity="center_vertical|fill_horizontal">
        <shape android:shape="rectangle"
            android:tint="@color/colorAccent">
            <corners android:radius="10dp"/>
            <size android:height="10dp" />
            <solid android:color="@color/colorAccent" />
        </shape>
    </item>

    <item android:id="@android:id/progress"
        android:gravity="center_vertical|fill_horizontal">
        <scale android:scaleWidth="100%">
            <selector>
                <item android:state_enabled="false"
                    android:drawable="@android:color/transparent" />
                <item>
                    <shape android:shape="rectangle"
                        android:tint="@color/colorPrimary">
                        <corners android:radius="8dp"/>
                        <size android:height="30dp" />
                        <solid android:color="@color/colorAccent" />
                    </shape>
                </item>
            </selector>
        </scale>
    </item>

</layer-list>

输出

enter image description here

  

注意

您可以根据需要更改 corners radius android:thumb