支持双向范围选择和普通模式的SeekBar
来源:互联网 发布:在线视频聊天源码 编辑:程序博客网 时间:2024/06/05 07:41
国际惯例先上图
作者的项目支持刻度和提示进度等。需要的可以戳
原作者Jay-Goo的项目GitHub地址
Step1
build.gradle增加
allprojects { repositories { ... maven { url 'https://jitpack.io' } }}dependencies { ... compile 'com.github.Jay-Goo:RangeSeekBar:v1.1.0'}//minSdkVersion的值改为16及以上minSdkVersion 16
Step2
xml增加
<LinearLayout 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" tools:context="com.xy.rangeseekbar.MainActivity" android:orientation="vertical" android:gravity="center" android:background="#e5e5e5" > <TextView android:id="@+id/progress2_tv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:background="@drawable/btn_dialog_box" /> <com.jaygoo.widget.RangeSeekBar android:id="@+id/seekbar2" android:layout_width="match_parent" android:layout_height="wrap_content" app:lineColorSelected="@color/colorPrimary" app:lineColorEdge="@color/colorPrimaryDark" app:thumbSize="20dp" app:seekBarHeight="10dp" app:cellMode="number" app:seekBarMode="range" app:progressHintMode="alwaysHide" /></LinearLayout>
MainActivity.java中代码
public class MainActivity extends AppCompatActivity { private RangeSeekBar seekbar2; private TextView tv2; private DecimalFormat df = new DecimalFormat("0"); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); seekbar2 = (RangeSeekBar)findViewById(R.id.seekbar2); tv2 = (TextView)findViewById(R.id.progress2_tv); //设置范围 seekbar2.setRange(0,179); //设置初始值 seekbar2.setValue(50,100); seekbar2.setOnRangeChangedListener(new RangeSeekBar.OnRangeChangedListener() { @Override public void onRangeChanged(RangeSeekBar view, float min, float max, boolean isFromUser) { if (isFromUser) { tv2.setText(df.format(min) + "-" + df.format(max)); seekbar2.setLeftProgressDescription(df.format(min)); seekbar2.setRightProgressDescription(df.format(max)); } } }); }}
用于显示选择范围的是一个TextView,考虑到它可能会被拉伸,所以背景用的是一张.9图片,制作.9图片教程请戳这里
参数设置
Float.MIN_VALUE
<= min < max,默认:0maxfloat最大值, min < max <= Float.MAX_VALUE
, 默认: 100reservefloat两个按钮的最小间距cellsintcells 等于0为普通模式,大于1时切换为刻度模式progressHintModeenum进度提示模式 defaultMode:当拖动时显示 alwaysHide:一直隐藏 alwaysShow:一直显示lineColorSelectedcolor拖动后的Seekbar颜色lineColorEdgecolor默认的Seekbar颜色thumbPrimaryColorcolor进度为最小值或最大值时按钮的颜色,默认:不调用thumbSecondaryColorcolor进度不为最小值或最大值时按钮的颜色,默认:不调用markTextArrayreference刻度文字,不设置的时候默认隐藏按钮的背景资源,不设置的时候默认为圆形按钮thumbResIdreference按钮的背景资源,不设置的时候默认为圆形按钮progressHintResIdreference进度提示背景资源,必须使用 9 path文件textPaddingdimension刻度文字与进度条之间的距离textSizehintBGHeightdimension进度提示背景的高度,不设置时根据文字尺寸自适应hintBGWithdimension进度提示背景的宽度,不设置时根据文字尺寸自适应hintBGPaddingdimension进度提示背景和进度条之间的距离seekBarHeightdimension进度条的高度thumbSizedimension按钮的尺寸cellModeenum刻度模式 number 根据刻度的实际所占比例分配位置*(markTextArray中必须都为数字)* other 平分当前布局*(markTextArray可以是任何字符)*seekBarModeenum单向、双向模式 single 单向模式,只有一个按钮 range 双向模式,有两个按钮源码下载
本文Demo源码下载
阅读全文
0 0
- 支持双向范围选择和普通模式的SeekBar
- 双向滑动的范围选择条SeekBar
- 双向滑动的范围选择条SeekBar
- Kotlin-->范围选择进度条, 双向SeekBar
- 自定义SeekBar使用双向滑块选择
- 一款美观的自定义SeekBar,支持单、双向、阶段滑动、刻度、负数等多种强大自定义属性
- SeekBar的使用和竖向的SeekBar
- Android双向seekbar
- MaterialRangeSlider双向拖动seekbar
- Android_自定义双向SeekBar
- 自定义双向滑动SeekBar
- C++ 9.2迭代器支持的运算和迭代器范围
- 安全模式和普通模式
- SeekBar的使用和自定义
- seekbar的secondaryprogress和progress
- 普通的代理模式
- android SeekBar 的基本应用和自定义SeekBar
- Notepad++支持列选择模式
- Qt4.7.0 使用电容屏
- Java 里如何实现线程间通信
- ImageLoader 图片加载框架
- linux 打开文件数 too many open files 解决方法
- html笔记
- 支持双向范围选择和普通模式的SeekBar
- SQLSERVER排查CPU占用高的情况
- 文件处理命令less
- C++设计模式感想
- 幽默笑话-傻冒-猿粪啊
- 【python学习笔记】多维数组初始化
- spring-data-redis使用jdk序列化时increment的异常
- JAVA进程占用高内存原因分析与优化方法
- JavaWeb三种常用的定时任务简单示例