雙向選擇的進度條

DoubleHeadedDragonBar(土嗨控件)

能夠修改樣式,支持自定義氣泡view。
用的上的能夠戳這裏github地址php


樣式


屬性

<?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

DoubleHeadedDragonBar bar,bar1;
    TextView testView,testView1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final int maxValue = 6;
        bar = findViewById(R.id.bar);
        //設置單位刻度顯示
        bar.setUnit("0公斤", "6公斤");
        bar.setCallBack(new DoubleHeadedDragonBar.DhdBarCallBack() {

            @Override
            public String getMinMaxString(int value, int value1) {
                return value + "~" + value1;
            }


            @Override
            public void onEndTouch(float minPercentage, float maxPercentage) {

            }
        });
        //設置氣泡按鈕
        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);
    }
複製代碼
相關文章
相關標籤/搜索