触摸事件的传播
我有一些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 事件,但是 TextView 根据其选择器更改其背景)。有什么想法告诉系统不要将触摸事件从父视图传播到子视图吗?
I've got some ListView
. Each list element is constructed using layout looking like this:
<SomeRootLayout android:background="@layout/some_other_selector">
<TextView android:background="@layout/some_selector"/>
<TextView android:background="@layout/some_selector"/>
<ImageView/>
</SomeRootLayout>
The some_selector.xml
is looking like this:
<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>
Now, when the user press the entire row, the each TextView is being pressed as well (not really pressed - no onClick events are generated, however TextViews change its background according to their selectors). Any ideas to tell system NOT to propagate touch events from parent to child views?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在 textview 上设置
android:duplicateParentState="false"
You can set
android:duplicateParentState="false"
on your textview