为什么当另一个布局覆盖它时,按钮可以点击?(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 screenAlthough 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
发布评论