900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > android遥控杆控件 Android自定义滑杆控件SeekBar多功能版本

android遥控杆控件 Android自定义滑杆控件SeekBar多功能版本

时间:2021-11-14 16:10:54

相关推荐

android遥控杆控件 Android自定义滑杆控件SeekBar多功能版本

在应用开发中有没有遇到过通过滑杆控件选择一些区间条件实现参数变化?今天我们就来自定义View实现一个多功能又实用的版本SeekBar。

Paste_Image.png

](http://upload-images.jianshu.io/upload_images/3982371-7f76b66f235bde86.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

1.在布局中直接使用

xmlns:tools="/tools"

xmlns:app="/apk/res-auto"

android:id="@+id/activity_main"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:gravity="center_horizontal"

android:padding="20dp"

tools:context="com.tangyx.seekbar.MainActivity"

android:orientation="vertical">

android:layout_marginTop="50dp"

android:layout_marginLeft="50dp"

android:layout_marginRight="50dp"

android:layout_width="match_parent"

android:layout_height="wrap_content">

android:id="@+id/only_back"

android:layout_width="match_parent"

android:layout_height="50dp"

app:tickCount="2"/>

...

android:id="@+id/time_layout"

android:layout_marginTop="30dp"

android:layout_marginLeft="5dp"

android:orientation="vertical"

android:layout_width="match_parent"

android:layout_height="wrap_content">

android:id="@+id/time_bar"

android:layout_width="match_parent"

android:layout_height="wrap_content"

app:tickCount="5"

app:tickHeight="3dp"

android:layout_marginLeft="10dp"

android:layout_marginRight="10dp"

app:connectingLineColor="@android:color/black"

app:barColor="@color/color_e0e8ee"

app:barWeight="1.5dp"/>

2.自定义的SeekBar一共有两种

第一种在滑球上面显示当前选择模式,就是设置文字显示在滑球上(com.seekbar.sliding.text.TextSeekBar)。

第二种两边都可以滑动操作,比如选择一个时间区域(com.seekbar.sliding.SlidingSeekBar)。

支持的属性:

```

####3.监听滑杆事件,滑杆滑动变化通过OnRangeBarChangeListener接口来实现对应的逻辑

![Paste_Image.png](http://upload-images.jianshu.io/upload_images/3982371-cc462a93735fa7f7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

####4.设置滑球上的文字通过setCircleText()方法,只有TextSeekBar支持该方法。

![seekbar.gif](http://upload-images.jianshu.io/upload_images/3982371-6457b1c4f91470fc.gif?imageMogr2/auto-orient/strip)

当然类似这方面的自定义View都是通过监听手势实现对应的逻辑,你可以继承BaseSeekBar来定义自己的样式。

更多的了解请通过源码实践。

我是源码

如果你喜欢就一起来提供更多人性化的思路,我也将会努力实现更多超强体验的自定义控件。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。