国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

Android實(shí)現(xiàn)動(dòng)態(tài)定值范圍效果的控件

2019-12-12 05:15:43
字體:
供稿:網(wǎng)友

先來看看效果:

一、添加依賴庫的步驟

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í)或者工作帶來一定的幫助,如果有疑問大家可以留言交流。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 白银市| 广州市| 体育| 同心县| 石阡县| 子洲县| 资溪县| 长寿区| 安达市| 耿马| 绥芬河市| 崇信县| 汾阳市| 内乡县| 交口县| 西乌珠穆沁旗| 盐津县| 永安市| 洛南县| 崇义县| 盘锦市| 马尔康县| 册亨县| 大石桥市| 仪陇县| 兰溪市| 巧家县| 拜城县| 泽库县| 长阳| 南宫市| 广水市| 洛川县| 博爱县| 清河县| 三亚市| 明溪县| 郎溪县| 白银市| 岳普湖县| 桐乡市|