片段在另一个片段问题片段、问题

2023-09-12 06:56:19 作者:毕竟我不讨喜

当我展示一个片段(这是全屏幕#77000000 背景)在另一个片段(我们称之为主),我的主要片段仍然反应点击(我们可以点击一个按钮,即使我们没有看到它)。

When I'm showing one fragment (which is full screen with #77000000 background) over another fragment (let's call it main), my main fragment still reacts to clicks (we can click a button even if we don't see it).

问题:怎么prevent点击第一个(主)片段

Question: how to prevent clicks on first (main) fragment?

修改

不幸的是,我不能隐瞒主要片段,因为我使用的是透明背景的第二个片段(这样,用户可以看到位于后面)。

Unfortunately, I can't just hide main fragment, because I'm using transparent background on second fragment (so, user can see what located behind).

推荐答案

设置点击上的第二个片段的,以真正的财产。该视图将捕获的事件,以便它不会被传递给主片段。因此,如果在第二片段的观点是一个布局,这将是code:

Set clickable property on the second fragment's view to true. The view will catch the event so that it will not be passed to the main fragment. So if the second fragment's view is a layout, this would be the code:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true" />