ViewGroup(LinearLayout)和Child onClick事件未传递给ViewGroup

时间:2014-08-28 13:14:34

标签: android onclick viewgroup

我有一个LinearLayout有几个搜索栏作为孩子,在SeekBars我使用android:clickable=false,在LinearLayout上我有android:clickable=true和相应的{{1}然而,如果setOnClickListenner上的任何按下都没有触发SeekBars点击,我已经阅读了它应该在某个地方阅读并通过将LinearLayout替换为SeekBars进行测试并将Buttons属性设置为clickable,然后将点击冒泡到父级。 我的问题是为什么行为不相似?

编辑:添加了代码示例

布局:

false

的活动:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MyActivity">

<LinearLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <SeekBar

        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clickable="false"
        android:longClickable="false"
        android:focusable="false"
        />

    <Button
        android:layout_marginTop="10dp"
        android:clickable="false"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Click me!"/>


    </LinearLayout>

1 个答案:

答案 0 :(得分:0)

终于明白了你的要求我认为这会解决它。 SeekBar不可调焦,而Button是。

这就是您无法从SeekBar

中删除此行的原因
android:focusable="false"

允许此焦点可以使ButtonSeekBar函数在单击时的功能相同。