Android雙向滑動控件

一 效果圖


二 使用方法


  1. 在你root的gradle中添加引用
allprojects {
    repositories {
    ...
    maven { url "https://jitpack.io" }
    }
 }

然后在module的gradle中添加引用

dependencies {
    compile 'com.github.kaxi4it:BidirectionalSeekBar:1.0'
}
  1. 在你的布局文件中添加xml代碼如:
<com.guyj.BidirectionalSeekBar
    android:id="@+id/bSeekBar1"
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_margin="20dp"
    app:ball_left_solid_color="@android:color/white"
    app:ball_left_stroke_color="@android:color/black"
    app:ball_right_solid_color="@android:color/holo_green_light"
    app:ball_right_stroke_color="@android:color/holo_green_dark"
    app:ball_radius_size="8dp"
    app:ball_stroke_size="1dp"
    app:text_left_num="566"
    app:text_right_num="820"
    app:text_min_unit="1"
    app:pb_height="3dp"
    app:pb_within_color="@android:color/holo_blue_bright"
    app:pb_without_color="@android:color/holo_red_light"
    app:ball_left_drawable="@mipmap/ic_launcher"
    app:ball_right_drawable="@mipmap/ic_launcher"
    />

ball_left_solid_color 代表左側(cè)圓球的填充色
ball_left_stroke_color 代表左側(cè)圓球的邊框顏色
ball_right_solid_color 代表右側(cè)圓球的填充色
ball_right_stroke_color 代表右側(cè)圓球的邊框顏色
ball_radius_size 圓球半徑
ball_stroke_size 圓球邊框顯示寬度
text_left_num 進度條最小值 單位int
text_right_num 進度條最大值 單位int
text_min_unit 進度條可拖動的最小單位 單位int
pb_height 進度條高度
pb_within_color 雙向選中部分的進度條顏色
pb_without_color 雙向未選中部分的進度條顏色
ball_left_drawable 左側(cè)圓球可以引用圖片資源
ball_right_drawable 右側(cè)圓球可以引用圖片資源

目前版本使用中的關(guān)鍵點如下:
a. 如果使用圖片資源代替圓球,那么需要左右2個圓球全部被替換,左右2個圖片資源建議等寬等高,否則會出現(xiàn)你不想看到的結(jié)果,后續(xù)更新中可能會解決非等寬等高的圖片問題
b. 當用圖片資源替換圓球后,那么圓球半徑,邊框?qū)挾龋瑘A球顏色等屬性為失效不可用狀態(tài),你寫了也是白寫
c. 如果不需要使用圖片資源的話,請千萬不要填寫ball_left_drawable和ball_right_drawable屬性

  1. Activity中的數(shù)據(jù)回調(diào),通過該回調(diào)可以實時獲得進度條所選中范圍的值
bidirectionalSeekBar.setOnSeekBarChangeListener(new BidirectionalSeekBar.OnSeekBarChangeListener() {
    @Override
    public void onProgressChanged(int leftProgress, int rightProgress) {
        textView.setText("left=" + leftProgress + " right=" + rightProgress);
    }
});

三 最終章


希望該控件能解決您的雙向滑動需求
項目完整代碼在 https://github.com/kaxi4it/BidirectionalSeekBar 中可查看

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

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

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