为什么当另一个布局覆盖它时,按钮可以点击?(Why is a button clickable when theres another layout overlaying it?)

系统教程 行业动态 更新时间:2024-06-14 16:58:29
为什么当另一个布局覆盖它时,按钮可以点击?(Why is a button clickable when theres another layout overlaying it?)

我得到了一个相对定位的布局。 其中我得到了(现在)两件事情:

绑定到onClick事件的可点击按钮 覆盖整个屏幕的LinearLayout

虽然LinearLayout覆盖了按钮,但按钮仍然是可点击的。 即使叠加层中有另一个按钮。

我怎样才能避免这种情况?

I got a Layout which is relatively positioned. In it I got (by now) two things:

A Clickable Button which is bound to an onClick-Event A LinearLayout which is overlaying the full screen

Although the LinearLayout is overlaying the button, the button is still clickable. Even if there's another button in the overlay.

How can I avoid this?

最满意答案

覆盖视图(和布局)必须实现onClick侦听器才能捕获事件,否则事件将在底层视图上分派。

Alright I found an approach that works together with animation:

The Layout (shortened):

<RelativeLayout ...> <Button ... /> <LinearLayout android:id="@+id/underlay" android:background="#00ffffff" /> <LinearLayout android:id="@+id/overlay" ... /> </RelativeLayout>

Now when Fading In "overlay" it seems to be the best to have an invisible "underlay" which is immediately put to VISIBLE:

LinearLayout underlay = (LinearLayout)findViewById(R.id.underlay); underlay.setVisibility(View.VISIBLE); underlay.setOnClickListener(...); //now animate the overlay

更多推荐

LinearLayout,按钮,got,电脑培训,计算机培训,IT培训"/> <meta name="descripti

本文发布于:2023-04-15 03:17:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/aa16d9321b81195c685a7511ea886f16.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:布局   按钮   button   overlaying   layout

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!