防止单击更改SeekBar进度

编程入门 行业动态 更新时间:2024-10-24 18:29:01
本文介绍了防止单击更改SeekBar进度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在Android应用中使用的是 SeekBar 。当用户在 SeekBar 上的任意位置单击时,其进度值将更改。我只希望在用户滑动 SeekBar 拇指时更改进度值(就像iOS中的 UISlider 一样)。

I am using a SeekBar in my Android app. When a user single taps anywhere on the SeekBar, its progress value is changed. I only want the progress value to change when the user slides the SeekBar thumb (just like a UISlider in iOS).

我尝试设置 SeekBar 为假,但这没有用。如何实现所需的行为?

I have tried setting the clickable property of the SeekBar to false but that didn't work. How can I achieve the desired behavior?

推荐答案

我本周遇到了相同的问题,并使用自定义的SeekBar解决了该问题:遵循我的代码:

I faced the same issue this week and I resolved it using a custom SeekBar: following my code:

public class Slider extends SeekBar { private Drawable mThumb; public Slider(Context context) { super(context); } public Slider(Context context, AttributeSet attrs) { super(context, attrs); } @Override public void setThumb(Drawable thumb) { super.setThumb(thumb); mThumb = thumb; } @Override public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { if (event.getX() >= mThumb.getBounds().left && event.getX() <= mThumb.getBounds().right && event.getY() <= mThumb.getBounds().bottom && event.getY() >= mThumb.getBounds().top) { super.onTouchEvent(event); } else { return false; } } else if (event.getAction() == MotionEvent.ACTION_UP) { return false; } else { super.onTouchEvent(event); } return true; }}

希望这会有所帮助

更多推荐

防止单击更改SeekBar进度

本文发布于:2023-10-08 02:45:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1471283.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单击   进度   SeekBar

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!