Android的碎片重叠previous视图按钮监听器 [英] Android fragments overlap previous view and button listeners

查看:122
本文介绍了Android的碎片重叠previous视图按钮监听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个片段的活性的A内。

I have an activity A with a fragment A inside.

活动A使用布局X和片段A使用布局A.

Activity A uses layout X, and fragment A uses layout A.

code布局的X:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<fragment
    android:id="@+id/fragment1"
    android:name="android.app.DialogFragment"
    android:layout_width="wrap_content"
    android:layout_height="500dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="113dp"
    class="com.example.fragtester.FragA" />

</RelativeLayout>

布局A是刚刚的TextView +的LinearLayout。

Layout A is just textview + linearlayout.

我设置使用版面B另一个B片段。

I set up another fragment B that uses layout B.

现在,我使用下面的code的酶活性的改变片段:

Now that I use the following code in activity A to change the fragments:

Fragment f = new FragB();
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.fragment1, f);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
ft.addToBackStack(null); 
ft.commit();

我最终布局B布局的下显示。

I end up having layout B displaying under layout A.

所以我用的FrameLayout来包装片段布局X和使用

So I use a FrameLayout to wrap the fragment in layout X and use

ft.replace(R.id.FrameLayout1, f);

现在的观点是工作很好。虽然,另一个问题出现了。

Now the view is working nicely. Though, another problem arises.

虽然布局B叠布局的,但按键仍然有效。

Although layout B covers layout A, but the buttons are still active.

这意味着,当我查看布局B,我还可以点击布局的按钮,即使我没有看到它。

That means when I am viewing layout B, I can still click buttons on layout A, even if I am not seeing it.

甚至当我添加片段C / D / E .....(布局C / D / E ....),在布局的按钮仍然有效。

And even when I add fragment C/D/E..... (layouts C/D/E....), the buttons on layout A is still active.

任何人能解释这是为什么?我使用的片段错?谢谢!

Can anybody explain why is that? Am I using fragments wrongly? Thanks!

通过获得的方法是进行布局的空白,并使用其他布局来覆盖它。不过,这并不似乎是正确的方式??

A way to get through is to make layout A blank, and use other layout to cover it. But it doesn't seems to be the "right" way??

推荐答案

删除片段,并添加的FrameLayout

Remove the fragment and add a FrameLayout

   <FrameLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ffffff" >
    </FrameLayout>

再加入片段编程。

then add fragments programmatically.

在Android的片段按钮单击闯关片段(我不知道如果这些片段假设这样的工作)。我以前在这种情况下做的是使该片段可点击的布局。因此点击次数不会通过。

In android fragment button click pass through the fragments (i dont know if the fragments are suppose to work like that). what I used to do in such a situation is to make the layout of the fragment clickable. so the clicks wont pass through.

这篇关于Android的碎片重叠previous视图按钮监听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆