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

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

635f10728761

Paste_Image.png

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

1.在布局中直接使用

xmlns:tools="http://schemas.android.com/tools"

xmlns:app="http://schemas.android.com/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来定义自己的样式。

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

我是源码

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值