首页 > 解决方案 > RangeSlider 自定义设计 - Android

问题描述

我想自定义RangeSlider. 我已经有了一个设计SeekBar,现在我想将其转换为RangeSlider. 对于这么小的任务,我认为使用库是不合理的。

我想要达到的结果。查看 SeekBar 的图片 在此处输入图像描述

搜索栏 Xml XML

    <SeekBar
        android:id="@+id/seek_bar_frost_hard_temperature"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:progressDrawable="@drawable/custom_seekbar_frost_hard"
        android:layout_marginTop="@dimen/margin_padding_size_small"
        android:layout_marginBottom="@dimen/margin_padding_size_small"
        android:max="11"
        android:splitTrack="false"
        android:maxHeight="@dimen/seek_bar_height"
        android:paddingStart="@dimen/margin_padding_size_xsmall"
        android:paddingEnd="@dimen/margin_padding_size_xsmall"
        android:progress="0"
        android:thumb="@drawable/seekbar_frost_hard_thumb"/>

custom_seekbar_frost_hard.xml

<?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/frost_hard_seekbar_background_color">
            <size android:height="@dimen/frost_seekbar_height" />
            <solid android:color="@color/frost_hard_seekbar_background_color" />
        </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/frost_hard_seekbar_progress_color">
                        <size android:height="30dp" />
                        <solid android:color="@color/frost_hard_seekbar_progress_color" />
                    </shape>
                </item>
            </selector>
        </scale>
    </item>
</layer-list>

seekbar_frost_hard_thumb.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Background -->
    <item>
        <shape>
            <solid android:color="@color/black"/>
            <size
                android:width="4dp"
                android:height="@dimen/seekbar_thumb_frost_hard_height" />
        </shape>
    </item>
</layer-list>

标签: androidxmlandroid-seekbarrangeslider

解决方案


推荐阅读