gpt4 book ai didi

android - 增加 SeekBar 的触摸优先级

转载 作者:行者123 更新时间:2023-11-29 15:28:54 25 4
gpt4 key购买 nike

我在 Horizo​​ntalScrollView 中有一个 SeekBar,我发现很难捕获 handle 并移动它。如果我没有准确触摸 handle ,Horizo​​ntalScrollView 将接收并使用触摸事件。有没有一种方法可以增加 SeekBar 的优先级,使其具有正常的触摸事件“范围”,或者这只是一个坏主意/设计,我应该避免吗?

最佳答案

这是解决此问题的另一种方法,无需扩展框架布局。
这个想法是在触摸 SeekBar 时禁用 Horizo​​ntalScrollView 的触摸事件。
因此,例如,当您初始化 View 时,您可以定义如下内容:

protected void onCreate(final Bundle savedInstanceState)
{

[...]

final HorizontalScrollView scrollView = (HorizontalScrollView) findViewById(R.id.vo_cw_hsv);
final SeekBar opacitySeekBar = (SeekBar) findViewById(R.id.vo_cw_seekbar);
opacitySeekBar.setOnTouchListener(new OnTouchListener()
{
@Override
public boolean onTouch(final View view, final MotionEvent event)
{
if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE)

scrollView.requestDisallowInterceptTouchEvent(true);

return false;
}
});

[...]

}

有关更多信息,您可以阅读有关 ViewParent 类的文档: http://developer.android.com/reference/android/view/ViewParent.html#requestDisallowInterceptTouchEvent(boolean)

关于android - 增加 SeekBar 的触摸优先级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9000068/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com