如何自定义滑块?

时间:2019-01-10 12:35:04

标签: java android xml android-drawable

我希望滑块的渐进部分像图片一样。我想用xml做到这一点。当我看图片时,看到每个像素是不同的颜色。我为每个像素画了一条单独的线。

enter image description here

我已经写了下面的代码来做到这一点。

<SeekBar
     android:layout_width="500dp"
     android:layout_height="match_parent"
     android:progressDrawable="@drawable/slider_style" />

=> drawable / slider_style

<?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/slider_background"/>
<item android:id="@android:id/progress">
    <clip android:drawable="@drawable/slider_progress" />
</item>

</layer-list>

=> drawable / slider_progress

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:top="2dp">
        <shape android:shape="line">
            <stroke
                android:color="#cfdbed"
                android:width="1dp"
                />
            <size
                android:height="1dp"
                />
        </shape>
    </item>
    <item android:top="1dp">
        <shape android:shape="line">
            <stroke
                android:color="#5f87c3"
                android:width="1dp"
                />
            <size
                android:height="1dp"
                />
        </shape>
    </item>
    <item>
        <shape android:shape="line">
            <stroke
                android:color="#3f71b9"
                android:width="1dp"
                />
            <size
                android:height="1dp"
                />
        </shape>
    </item>
    <item android:bottom="1dp">
        <shape android:shape="line">
            <stroke
                android:color="#4374ba"
                android:width="1dp"
                />
            <size
                android:height="1dp"
                />
        </shape>
    </item>
    <item android:bottom="2dp">
        <shape android:shape="line">
            <stroke
                android:color="#b4c7e3"
                android:width="1dp"
                />
            <size
                android:height="1dp"
                />
        </shape>
    </item>
</layer-list>

结果: enter image description here

如您所见,像素中的颜色看起来不同。我在哪里出错?

0 个答案:

没有答案