[英]How do I prevent a ListView from receiving clicks when another View or Fragment is over it?
I have a ListView that displays some data.我有一个显示一些数据的 ListView。 The rows can be clicked as well.也可以单击行。 I also have a custom Fragment at the bottom of the screen that "hovers" over the ListView all the time.我还在屏幕底部有一个自定义 Fragment,它一直“悬停”在 ListView 上。 I want this Fragment to also pick up click events so that I can do stuff when it's clicked.我希望这个 Fragment 也能接收点击事件,这样我就可以在点击它时做一些事情。
The issue is that I can't figure out how to do that, and the ListView ends up getting the click instead, even when the Fragment covers that particular row.问题是我不知道如何做到这一点,并且 ListView 最终获得了点击,即使 Fragment 覆盖了该特定行。
Basically, I want to make sure that when there is a Fragment (or even another View) on top of the ListView, that Fragment registers the click when I click on it, and not the ListView.基本上,我想确保当 ListView 顶部有一个 Fragment(甚至另一个 View)时,该 Fragment 在我点击它时注册点击,而不是 ListView。 How do I do this?我该怎么做呢?
If another View or Fragment is over it, you can prevent clicks from reaching through by setting the android:clickable
attribute to true
on the root of the layout that is presented on top of something else clickable.如果另一个 View 或 Fragment 在它上面,你可以通过在布局的根上设置android:clickable
属性为true
来防止点击到达,该布局的根显示在其他可点击的东西之上。
The same goes for the layout inflated in the Fragment displayed on top of something else, just set android:clickable
to true on the root of the inflated layout.对于在其他内容顶部显示的 Fragment 中膨胀的布局也是如此,只需在膨胀布局的根上将android:clickable
设置为 true 即可。
android:clicable="true"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.