先來看看效果:

一、添加依賴庫的步驟
1.項(xiàng)目的gradle文件內(nèi)的做以下改動(dòng)
allprojects { repositories { ... maven { url "https://jitpack.io" } } }2.添加最新版本的依賴庫,最新版本如右所示,修改末尾的版本即可(因?yàn)槲矣袝r(shí)候更新版本了會(huì)忘記修改readme)
dependencies { compile 'com.github.Brioal:BrioalSetting:1.0' ////例如上面最新版本是1.1,則只要把1.0改成1.1即可使用最新版本 }二、使用步驟:
1.xml布局文件
實(shí)際使用過程中發(fā)現(xiàn)如果與其他組件在一起,則滑動(dòng)事件會(huì)實(shí)效,暫時(shí)沒發(fā)現(xiàn)代碼里面怎么解決,設(shè)置focus啥的都沒用,暫時(shí)的解決辦法是給組件添加一個(gè)父布局并且不包含其他組件即可,如下:
<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.代碼設(shè)置
mRangeBar = (RangeBar) findViewById(R.id.main_container); //添加數(shù)據(jù)源 final List<RangeEntity> list = new ArrayList<>(); //要顯示的文字和實(shí)際的值,分別是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)); //設(shè)置數(shù)據(jù)源 mRangeBar.setValues(list); //添加范圍改變監(jiān)聽器 mRangeBar.addOnRangeChangedListener(new OnRangeChangedListener() { @Override public void selected(int startIndex, int endIndex) { //獲取到的是起始和終止的數(shù)據(jù)在List中所對應(yīng)的下標(biāo) mTvMin.setText(list.get(startIndex).getValue() + ""); mTvMax.setText(list.get(endIndex).getValue() + ""); } });3.提供的供自定義視圖的方法
方法 功能void addOnRangeChangedListener(OnRangeChangedListener listener) 設(shè)置事件監(jiān)聽器void setLineColor(int lineColor) 設(shè)置中間的線條顏色void setLineWidth(int lineWidth) 設(shè)置中間的線條寬度void setCircleColor(int circleColor) 設(shè)置圓點(diǎn)的邊框顏色void setCircleRadius(int circleRadius) 設(shè)置圓點(diǎn)的半徑void setCircleWidth(int circleWidth) 設(shè)置圓點(diǎn)的線條寬度void setCenterColor(int centerColor) 設(shè)置選中的圓點(diǎn)的填充顏色void setPointColor(int pointColor) 設(shè)置游標(biāo)的填充顏色void setStartIndex(int startIndex) 設(shè)置選中的起始下標(biāo)int getStartIndex() 獲取選中的起始下標(biāo)void setEndIndex(int endIndex) 設(shè)置終止下標(biāo)int getEndIndex() 獲取終止的下標(biāo)
總結(jié)
以上就是這篇文章的全部內(nèi)容,希望本文能對大家的學(xué)習(xí)或者工作帶來一定的幫助,如果有疑問大家可以留言交流。
新聞熱點(diǎn)
疑難解答
圖片精選