Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android SeekBar';当不触摸时,s状态变为按下状态_Android_Android View_Android Seekbar - Fatal编程技术网

Android SeekBar';当不触摸时,s状态变为按下状态

Android SeekBar';当不触摸时,s状态变为按下状态,android,android-view,android-seekbar,Android,Android View,Android Seekbar,这是may layout xml: <RelativeLayout android:id="@+id/seek_bar_wrapper" android:layout_width="match_parent" android:layout_height="200dip"> <SeekBar android:id="@+id/seek_bar" android:layout_width="match_parent"

这是may layout xml:

<RelativeLayout
    android:id="@+id/seek_bar_wrapper"
    android:layout_width="match_parent"
    android:layout_height="200dip">

    <SeekBar
        android:id="@+id/seek_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_margin="20dip"
        android:maxHeight="2dip"
        android:minHeight="2dip"
        android:progressDrawable="@drawable/drawable_seekbar_progress"
        android:thumb="@drawable/drawable_seekbar_thumb" />
</RelativeLayout>

我将
OnClickListener
设置为
RelativeLayout
。奇怪的是,当我触摸
RelativeLayout
时,
SeekBar
的性能就像我按下它一样,当按下它的状态时,它的拇指变成了可绘制的。我想这是国家变得紧迫的时候了


这是一个bug吗?如何处理?

视图组在可单击时,似乎会将其状态传递给孩子,如本问题所示:

这可能是因为您将
OnClickListener
设置为
RelativeLayout

我的第一个倾向是在
SeekBar
后面放置一个
按钮,作为
SeekBar
的兄弟,并将其用于OnClick操作

您还可以覆盖您的
RelativeLayout
,在
setPressed

根据文件:

在ViewGroup中处理触摸事件需要特别小心,因为它是 视图组中的子对象是不同视图的目标的情况很常见 触摸事件,而不是查看组本身。确保每个视图 正确接收针对它的触摸事件,覆盖 onInterceptTouchEvent()方法

所以这似乎是有意的行为。如果要避免此行为,您可能需要覆盖
视图组(
RelativeLayout
)或使用一个
视图,该视图不是此事件的
SeekBar
的父视图。

刚刚设置

 android:clickable="true"
 android:focusable="true"

对于你的seekbar

我看到,自从我发布了这个答案后,你还提出了3个问题。如果这有助于你,请接受答案,这样我们都可以得到代表,如果不让我知道你哪里有麻烦。这解决了我的问题,谢谢Vadim!!出于某种原因,这实际上是可行的