如何在 Android 中禁用 SlidingDrawer 后面的视图?
我有一个 SlidingDrawer,它从屏幕底部弹出并填充屏幕约 80%。即使 SlidingDrawer 视图处于焦点状态,仍然可以单击 SlidingDrawer 后面的视图中的项目、按钮和其他元素。当 SlidingDrawer 处于活动/上拉/焦点状态时,我想禁用它后面的整个视图,这样它就无法接收点击和触摸。有没有好的方法来禁用整个视图?我尝试过 setEnable(false) 和 setClickable(false) 但它们都不起作用。
帮助?
I have a SlidingDrawer that pops up from the bottom of the screen and fills the screen about 80%. Even though the SlidingDrawer view is in focus, it is still possible to click on items, buttons and other elements in the view that is behind the SlidingDrawer. When SlidingDrawer is active/pulled up/in focus, I want to disable the entire view behind it so it will not be able to recieve clicks and touches. Is there a good way to disable an entire view? I have tried setEnable(false) and setClickable(false) but neither of them work.
Help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这是解决这个问题的方法(我也需要一个解决方案) - 获取保存内容的 LinearLayout 并添加一个单击侦听器。让点击侦听器响应点击(扔掉,无论如何) - 然后这会阻止它传播到滑动抽屉下方的视图 - 它对我有用 - 并且它不会阻塞抽屉中的其他项目。
Here's a way to get around this problem (I needed a solution also) - grab the linearLayout that holds the contents and add a click listener. Have the click listener respond to clicks (throw away, whatever) - and this then stops it propagating to the view below the sliding drawer - it works for me - and it doesn't block the other items in the drawer.
在侧面布局中执行
android:clickable="true"
例如以下文件是
drawer.xml
内部
LinearLayout
android:id=" @+id/drawer_view"
clickable="true"
In side Layout do
android:clickable="true"
For Example Following file is
drawer.xml
Inside
LinearLayout
android:id="@+id/drawer_view"
clickable="true"
乔的回答对我没有帮助。我的情况有点不同。我有一个有两个孩子的 FrameLayout。在给定时刻,只有一个孩子必须处于“活动”状态,而当第二个孩子处于活动状态时,第一个孩子不应再处理任何输入。我的解决方案:
享受吧!
Joe's answer did not do the trick for me. My scenario is a bit diferent. I have a FrameLayout with two children. Only one of the children has to be 'active' at a given moment, and while the second is active the first should no longer process any input. My solution:
Enjoy!
我尝试将
SlidingDrawer
放入RelativeLayout
中,而不是LinearLayout
中。并设置打开方法中的
mySlidingDrawer.bringToFront()
。所以我认为这可能是一个解决方案。
I've tried to put
SlidingDrawer
in theRelativeLayout
, instead ofLinearLayout
. And setmySlidingDrawer.bringToFront()
in opening method.So I think this may be a solution.
我不知道这是否有效,但值得一试。称呼
setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS)< /a> 在容器视图(滑动抽屉滑过的视图)上。
I don't know if this will work, but it's worth a try. Call
setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS) on your container View (the one that the sliding drawer slides over).