1

I would like to have a nested fragment which should take the rest of the space. The problem is that it even doesn't show because the height is 1 px. If I set the height to 300 dp for example everything looks ok. Here is my code. Maybe the layout cannot calculate what is the height of the other two layouts.:

          <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="5dp"
            android:orientation="vertical">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/white_with_divider_bg"
                android:id="@+id/firstL">

            </RelativeLayout>

            <RelativeLayout
                android:id="@+id/secondL"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp">

            </RelativeLayout>

            <FrameLayout
                android:id="@+id/child_fragment"
                android:layout_height="0dip"
                android:layout_width="match_parent"
                android:layout_weight="1"/>

        </LinearLayout>

It should look like this:

enter image description here

charbinary
  • 1,875
  • 4
  • 17
  • 25
  • Instead of using all those nested layouts (bad for performances and poor design), you can use a single RelativeLayout. Or even a single LinearLayout (which is also faster), in this case. – Phantômaxx Nov 14 '16 at 10:42
  • The layout is complex with a lot of views inside every sub layout and for this reason I have showed the main logic only. – charbinary Nov 14 '16 at 10:45
  • For what you have shown, a single LL is enough. If it is more complex, consider using a single RL. – Phantômaxx Nov 14 '16 at 11:08

1 Answers1

0

When working with weights all children of the LiniearLayout should have a weight, but that wouldnt help you. You should have android:id="@+id/child_fragment" have height="match_parent" and remove the weight.

That should work.

miqueloi
  • 688
  • 4
  • 13
  • Hmm. Another solution you can try is to replace LiniearLayout with a RelativeLayout and use the above and below properties you can give the children. – miqueloi Nov 14 '16 at 10:45