android 自定義view seekbar


雙向選擇;
支持氣泡功能,氣泡文字,背景樣式可以自定義;
進度條按鈕,顏色,寬度在xml中設(shè)置;


GitHub地址」用的上的話,點star不迷路,小老弟跪求了~

樣式

在這里插入圖片描述

使用

Grade

    allprojects {
        repositories {
            ...
            maven { url 'https://www.jitpack.io' }
        }
    }
        
        dependencies {
            implementation 'com.github.yujinzhao123:DoubleHeadedDragonBar:1.0.4'
    }

Maven

    <repositories>
        <repository>
            <id>jitpack.io</id>
            <url>https://www.jitpack.io</url>
        </repository>
    </repositories>
        
       <dependency>
        <groupId>com.github.yujinzhao123</groupId>
        <artifactId>DoubleHeadedDragonBar</artifactId>
        <version>1.0.4</version>
    </dependency>

屬性

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="DoubleHeadedDragonBar">
        <!--進度條按鈕寬高-->
        <attr name="button_width" format="dimension" />
        <attr name="button_height" format="dimension" />
        <!--進圖條按鈕圖片-->
        <attr name="button_img" format="reference"/>
        <!--單位字體顏色-->
        <attr name="text_color" format="color"/>
        <!--進圖條背景顏色-->
        <attr name="bg_color" format="color"/>
        <!--進度條顏色-->
        <attr name="value_color" format="color"/>
        <!--進度條寬-->
        <attr name="seek_height" format="dimension"/>
    </declare-styleable>

</resources>

案layout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    android:background="#fff"
    tools:context=".MainActivity">
    <cn.bar.DoubleHeadedDragonBar
        android:layout_margin="10dp"
        android:id="@+id/bar"
        app:text_color="#5C6980"
        app:button_img="@drawable/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <cn.bar.DoubleHeadedDragonBar
        android:layout_below="@+id/bar"
        android:layout_margin="10dp"
        android:id="@+id/bar1"
        app:text_color="#1B97F7"
        app:button_img="@mipmap/seek_button"
        app:button_height="40dp"
        app:button_width="40dp"
        app:bg_color="#999"
        app:value_color="#e97051"
        app:seek_height="6dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</RelativeLayout>

Activity

 
        final int maxValue = 6;
        bar = findViewById(R.id.bar);
        //設(shè)置單位刻度顯示
        bar.setUnit("0公斤", "6公斤");
        bar.setCallBack(new DoubleHeadedDragonBar.DhdBarCallBack() {
            //返回氣泡顯示文字
            @Override
            public String getMinMaxString(int value, int value1) {
                return value + "~" + value1;
            }
            //結(jié)束觸摸 按百分比返回選擇值,范圍 0~100
            @Override
            public void onEndTouch(float minPercentage, float maxPercentage) {
            }
        });
        //設(shè)置氣泡按鈕
        testView2 = (TextView) LayoutInflater.from(this).inflate(R.layout.toast_view, null);
        bar.setToastView2(testView2);

        testView = (TextView) LayoutInflater.from(this).inflate(R.layout.toast_view, null);
        bar.setToastView(testView);
        testView.setText("0");
        testView1 = (TextView) LayoutInflater.from(this).inflate(R.layout.toast_view, null);
        bar.setToastView1(testView1);
        testView1.setText("6");


        bar1 = findViewById(R.id.bar1);
        bar1.setUnit("0", "100");
        bar1.setMinValue(10);
        bar1.setMaxValue(80);
    }
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容