【问题标题】:Propagation of touch events触摸事件的传播
【发布时间】:2011-08-26 08:54:24
【问题描述】:


我有一些ListView。每个列表元素都是使用如下布局构造的:

<SomeRootLayout android:background="@layout/some_other_selector">
    <TextView android:background="@layout/some_selector"/>
    <TextView android:background="@layout/some_selector"/>
    <ImageView/>
</SomeRootLayout>

some_selector.xml 看起来像这样:

<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_pressed="true" android:drawable="@drawable/ic_btn_stop_pressed" />

    <item android:drawable="@drawable/ic_btn_stop_default" />
</selector>

现在,当用户按下整行时,每个 TextView 也会被按下(不是真正按下 - 不会生成 onClick 事件,但是 TextViews 根据其选择器更改其背景)。有什么想法告诉系统不要将触摸事件从父视图传播到子视图?

【问题讨论】:

  • 尝试创建自定义 ListView,覆盖 dispatchTouchEvent 并在那里调用 super 方法,但返回 true 以防止传播。
  • 我在这里找到了解决方案stackoverflow.com/questions/6741908/…

标签: android touch event-propagation


【解决方案1】:

你可以在你的文本视图上设置android:duplicateParentState="false"

【讨论】:

  • 视图是否有按下状态不依赖于duplicateParentState。
猜你喜欢
  • 2014-01-18
  • 2012-10-12
  • 1970-01-01
  • 1970-01-01
  • 2011-01-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多