自定义SeekBar实现标尺指示范围的功能(含自定义shape等资源)
来源:互联网 发布:休闲食品网络市场调查 编辑:程序博客网 时间:2024/06/06 01:35
要实现的功能请看图:
1.要实现这个功能就必须要禁止掉SeekBar的拖拽,所以在这里就选择集成自SeekBar,重写其onTouchEvent()方法,将返回值改为false表示处理拖拽事件,将事件往上传递。
import android.content.Context;import android.util.AttributeSet;import android.view.MotionEvent;import android.widget.SeekBar;/** * Created by Avater on 2017/3/14. * 自定义SeekBar,禁止用户拖动达到指示血压范围的效果 */public class MySeekBar extends SeekBar { public MySeekBar(Context context) { super(context); } public MySeekBar(Context context, AttributeSet attrs) { super(context, attrs); } public MySeekBar(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @Override public boolean onTouchEvent(MotionEvent event) { return false; }
2.在布局文件中使用:
<cn.appscomm.pedometer.avater.MySeekBar android:id="@+id/blood_limit" android:layout_width="match_parent" android:layout_height="20dp" android:progress="32"android:max="99"android:progressDrawable="@drawable/seek_list" android:thumb="@drawable/flag_green" />
3.编写seek_list资源文件,(android:thub->表示自定义的图标(自己选择合适的即可)),在drawable文件下->新建Drawable Resouces file ->layer-list(文件类型):seek_list
<?xml version="1.0" encoding="utf-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@android:id/background" android:paddingBottom="3px" android:paddingTop="3px"> <shape> <corners android:radius="10dip" /> <gradient android:angle="270" android:centerColor="@android:color/transparent" android:centerY="0.45" android:endColor="@android:color/transparent" android:startColor="@android:color/transparent" /> </shape> </item> <item android:id="@android:id/progress" android:paddingBottom="3px" android:paddingTop="3px"> <clip> <shape> <corners android:radius="10dip" /> <gradient android:angle="270" android:centerColor="@android:color/transparent" android:centerY="0.45" android:endColor="@android:color/transparent" android:startColor="@android:color/transparent" /> </shape> </clip> </item></layer-list>
4.在方法中调用:
/** * 以舒张压为标准 * * @param progress 低压(progress<60),正常(60<progress<90),高压(大于90) * @deprecated 将MySeek的最大值设置为99,平均三等分,根据比例算出对应的进度值 */private void setSeekBarProgessAndPng(int progress) { int progr = 0; if (progress < 60) { progr = progress * (33 / 60); blood_limit.setThumb(getResources().getDrawable(R.drawable.flag_green)); } if (progress >= 60 && progress < 90) { progr = 33 + (progress - 60) * (33 / 30); blood_limit.setThumb(getResources().getDrawable(R.drawable.flag_yellow)); } if (progress >= 90) { progr = 66 + (33 / 10) * (progress - 90); blood_limit.setThumb(getResources().getDrawable(R.drawable.flag_red)); } blood_limit.setProgress(progr);}
完毕,谢谢支持!
0 0
- 自定义SeekBar实现标尺指示范围的功能(含自定义shape等资源)
- 自定义带标尺的seekbar
- Android自定义shape资源
- 自定义SeekBar样式实现
- 实现自定义SeekBar
- 各种自定义进度条(progressbar或seekbar)的实现
- 自定义SeekBar(ProgressBar实现SeekBar效果)去除两边间距
- SeekBar 的自定义样式
- 自定义竖着的SeekBar
- 自定义风格的SeekBar
- 自定义Seekbar的注意事项
- 自定义半圆的SeekBar
- 自定义SeekBar的外观
- 自定义seekBar的样式
- 自定义seekBar(一)
- Android 自定义标尺控件(选择身高、体重等)
- 自定义View实现环形SeekBar
- 自定义View实现环形SeekBar
- D
- idea build 无war包
- 内部类
- angularjs select 赋值 ng-options配置方式
- iOS 开发简单, 工资高。 用户群体消费水平高。Android 开发难很多,工资较低。
- 自定义SeekBar实现标尺指示范围的功能(含自定义shape等资源)
- 1079. Total Sales of Supply Chain (25)
- 1004. 成绩排名 (20)
- 语音学习笔记10------如何利用Deep CNN大幅提升识别准确率?
- 计算机硬件软件dos基础常识
- CentOS配置hadoop
- 进入某个目录需要什么权限
- 北邮OJ-97. 二叉排序树-12计院上机C
- shell脚本之if语句