创建具有三角形背景的自定义SeekBar

时间:2013-03-13 13:59:16

标签: android

我正在尝试创建一个带有三角形背景的自定义SeekBar。没有拇指图标。以下是我想要实现的一些图像

Empty SeekBar

3/4 Full SeekBar

Full SeekBar

以下是我目前的代码

RES /绘制对象/ segment_bg

<?xml version="1.0" encoding="utf-8"?>
 <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <clip>
            <shape>
                <gradient
                    android:startColor="#FF5e8ea3"
                    android:centerColor="#FF32a0d2"
                    android:centerY="0.1"
                    android:endColor="#FF13729e"
                    android:angle="270"
                />
            </shape>
        </clip>
    </item>
</layer-list>

RES /绘制对象/段

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/background">
        <nine-patch
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:src="@drawable/slider"
            android:dither="true"
         />
    </item>
    <item android:id="@android:id/secondaryProgress">
        <clip>
            <shape>
                <gradient
                    android:startColor="#80028ac8"
                    android:centerColor="#80127fb1"
                    android:centerY="0.75"
                    android:endColor="#a004638f"
                    android:angle="270"
                />
            </shape>
        </clip>
    </item>
    <item
        android:id="@android:id/progress"
        android:drawable="@drawable/segment_bg"
    />
</layer-list>

activity.xml

<SeekBar
    android:id="@+id/frequency_slider"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="100dp"
    android:max="20"
    android:progress="0"
    android:secondaryProgress="0"
    android:progressDrawable="@drawable/segment"
/>

使用的9补丁图像是

9 Patch Slider

结果如下所示

Incorrect SeekBar

我的问题是如何让搜索条适合三角形?然后我如何删除拇指图标,不需要一个。

由于

0 个答案:

没有答案