Android snippets overlap previous view and button listeners
I have an activity A with fragment A inside.
Activity A uses layout X and slice A uses layout A.
layout 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>
Layout A is just textview + linearlayout.
I have installed another snippet B that uses layout B.
Now when 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();
I ended up with layout B displayed under layout A.
So I am using FrameLayout to wrap the fragment in layout X and use
ft.replace(R.id.FrameLayout1, f);
The view now works nicely. Another problem arises though.
Although layout B covers layout A, the buttons are still active.
This means that when I view layout B, I can still press buttons on layout A, even if I cannot see it.
And even when I add the C / D / E ..... snippet (C / D / E .... layouts) the buttons on layout A are still active.
Can someone explain why? Am I using fragments incorrectly? Thank!
An easy way to make the layout blank and use a different layout to cover it. But that doesn't seem like the "right" way.
source to share
Remove fragment and add FrameLayout
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff" >
</FrameLayout>
then add snippets programmatically.
In android fragment button click skip fragments (I don't know if fragments will work like this). what I did in a situation like this was to make the fragment layout clickable. so the clicks won't get through.
source to share