A fragment unintentionally behind other species

I have a container assembly as follows:

RelativeLayout container
--LinearLayout
  --TextView
--LinearLayout
  --Button
  --Button

And I'm trying to add a “ListFragment” snippet to the container by displaying the following LinearLayouts above it:

ListFragment listfragment = new ListFragment();
getFragmentManager().beginTransaction().replace(R.id.contianer,listfragment).commit();

Problem: This is not the case. It is displayed only above the second LinearLayout, and the first LinearLayout is still visible ABOVE.

This is how xmls:

Xml container:

<RelativeLayout
        android:id="@+id/contianer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_alignParentEnd="true"
        android:layout_below="@+id/container">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="20dp"
            android:paddingLeft="20dp"
            android:paddingRight="20dp"
            android:layout_marginLeft="0dp"
            android:id="@+id/linearLayout"
            android:layout_alignParentBottom="true"
            android:paddingTop="30dp">

            <Button
                android:id="@+id/back"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Button"
                android:textSize="30dp" />

            <Button
                android:id="@+id/nextButton"
                android:layout_width="match_parent"
                android:layout_height="80dp"
                android:layout_weight="0.5"
                android:text="Button"
                android:textSize="30dp"
                android:background="#009688"
                android:textColor="#ffffff" />
        </LinearLayout>

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/white"
            android:elevation="4dp"
            android:id="@+id/vanisherView"
            android:layout_centerHorizontal="true"
            android:layout_margin="20dp">

            <TextView
                android:id="@+id/erklareung"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textColor="@android:color/black"
                android:background="@android:color/white"
                android:padding="40dp"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textSize="35dp"
                android:layout_alignParentTop="true"
                android:layout_alignParentEnd="true" />

        </LinearLayout>


    </RelativeLayout>

The container is wrapped in a different layout, but I think it really matters.

Here is the xml snippet:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/black"
    android:id ="@+id/viewer_layout">

    <com.woxthebox.draglistview.DragListView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/drag_list_view"
        android:layout_width="match_parent"
        android:background="@android:color/black"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_height="match_parent"/>

</RelativeLayout>

Ive painted Fragment Black to see where it is shown and where not

Thanks for the answers and greetings.

+4
source share
2 answers

Fragment , .

FrameLayout, , Fragment , Fragment .

FrameLayout, , , , RelativeLayout.

:

<RelativeLayout android:id="@+id/container>"

    <FrameLayout android:id="@+id/fragment_container"/>

    <LinearLayout>
        <Button/>
        <Button/>
    </LinearLayout>

    <LinearLayout>
        <TextView/>
    </LinearLayout>

</RelativeLayout>
+3

FrameLayout

FrameLayout
--RelativeLayout   //layout with your views
--FrameLayout      //container for your fragment
0

Source: https://habr.com/ru/post/1615771/


All Articles