Android開源組件-動態效果定值範圍選擇控件

Android開源組件-動態效果定值範圍選擇控件

定值範圍選擇控件

效果演示:

添加依賴庫的步驟

1.項目的gradle文件內的做以下改動

allprojects {
        repositories {
            ...
            maven { url "https://jitpack.io" }
        }
    }

2.添加最新版本的依賴庫,最新版本如右所示,修改末尾的版本即可(因爲我有時候更新版本了會忘記修改readme)

dependencies {
            compile 'com.github.Brioal:RangeSeekBar:1.0'
            ////例如上面最新版本是1.1,則只要把1.0改成1.1即可使用最新版本
    }

使用步驟:

1.xml佈局文件

實際使用過程中發現如果與其他組件在一起,則滑動事件會實效,暫時沒發現代碼裏面怎麼解決,設置focus啥的都沒用,暫時的解決辦法是給組件添加一個父佈局並且不包含其他組件即可,如下:

 <LinearLayout
        android:id="@+id/layout"
android:layout_centerInParent="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <com.brioal.rangeseek.view.RangeBar
            android:id="@+id/main_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"/>

    </LinearLayout>

2.代碼設置

  mRangeBar = (RangeBar) findViewById(R.id.main_container);
          //添加數據源
        final List<RangeEntity> list = new ArrayList<>();
        //要顯示的文字和實際的值,分別是String 和 Object類型
        list.add(new RangeEntity("15℃", 15));
        list.add(new RangeEntity("18℃", 18));
        list.add(new RangeEntity("21℃", 21));
        list.add(new RangeEntity("24℃", 24));
        list.add(new RangeEntity("27℃", 27));
        list.add(new RangeEntity("30℃", 30));
        //設置數據源
        mRangeBar.setValues(list);
        //添加範圍改變監聽器
        mRangeBar.addOnRangeChangedListener(new OnRangeChangedListener() {
            @Override
            public void selected(int startIndex, int endIndex) {
            //獲取到的是起始和終止的數據在List中所對應的下標
                mTvMin.setText(list.get(startIndex).getValue() + "");
                mTvMax.setText(list.get(endIndex).getValue() + "");
            }
        });

3.提供的供自定義視圖的方法

方法 功能
void addOnRangeChangedListener(OnRangeChangedListener listener) 設置事件監聽器
void setLineColor(int lineColor) 設置中間的線條顏色
void setLineWidth(int lineWidth) 設置中間的線條寬度
void setCircleColor(int circleColor) 設置圓點的邊框顏色
void setCircleRadius(int circleRadius) 設置圓點的半徑
void setCircleWidth(int circleWidth) 設置圓點的線條寬度
void setCenterColor(int centerColor) 設置選中的圓點的填充顏色
void setPointColor(int pointColor) 設置遊標的填充顏色
void setStartIndex(int startIndex) 設置選中的起始下標
int getStartIndex() 獲取選中的起始下標
void setEndIndex(int endIndex) 設置終止下標
int getEndIndex() 獲取終止的下標

完畢~

寫在後面

1.我的其他的一些開源庫,有興趣的可以點進去看看給個star啥的

多達288種動畫效果定製的側滑菜單庫

仿京東首頁垂直跑馬燈組件

仿360底部菜單佈局

快速搭建設置界面開源庫

仿知乎首頁輪播組件

流式佈局,封裝用於顯示標籤

2.建了個交流Android開發的QQ羣,歡迎新手老手:羣號:375276053

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章