简体   繁体   English

当另一个 View 或 Fragment 在它上面时,如何防止 ListView 接收点击?

[英]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.

相关问题 如何在仍然接收鼠标点击时阻止表单窃取焦点? - How can I prevent a form from stealing focus while still receiving mouse clicks? 如何防止某些对象接收光线投射? - How do I prevent certain objects from receiving the raycast? 防止表单接收鼠标点击 - Prevent form from receiving mouse clicks 如果用户在C#中单击多次,如何防止按钮代码运行两次? - How do I prevent button code from running twice if the user clicks more than once in C#? 显示另一张表格时,如何防止原始表格失去焦点? - How do I prevent the original form from losing focus when I show another form? C#:当用户单击按钮时如何查看图像? - C#: How do I view an image when a user clicks on a button? 我如何从 MVVM WPF 中的视图 go 到另一个视图? - How do I go to another view from a view in MVVM WPF? 如何从列表视图中查看一个项目,当我单击列表视图的该项目时,它将在文本块上显示数据? - How can i view an item from a listview that when I click on that item of the listview it will show data on a textblock? 从一个视图切换到另一个视图时,如何保持用户控件的 Textbox Text 属性的值? - How do I persist the value of the Textbox Text property of a user control when switching from one view to another? 当用户单击最初不可见的单元格时,如何阻止datagridview猛烈地重新绘制? - How do I stop the datagridview from violently repainting when a user clicks on a cell that was not initially visible?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM