Kirmani88 Kirmani88 - 4 months ago 28
Android Question

Linear Layout inside Frame Layout stops working

My Layout is working fine, It has a parent

Linear Layout
and multiple
Linear Layouts
inside it.

Now i need to add a background image,So that i need to add a frame layout here.

When i change parent
Linear Layout
to
Frame Layout
, it disappears all the items in the
linear layout
.

If i add
Frame Layout
,inside
Linear Layout
it disappears all the items in the Linear layout.

I am unable to understand how to put a frame layout without removing Linear Layout items.

The Layout code is quite long.

I am putting above part of it.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="6"
android:orientation="vertical"
>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="80dp"
android:orientation="horizontal"
android:layout_marginTop="20dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
>

<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.8"
android:src="@drawable/image11"
/>

<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:paddingTop="10dp"

>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="7:00 PM CST"
android:layout_gravity="center"
android:gravity="center"
android:textColor="@color/white"
android:fontFamily="sans-serif-medium"
android:textSize="12sp"
/>

</LinearLayout>

<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.8"
android:src="@drawable/icon2"
/>

</LinearLayout>





<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal"
android:paddingLeft="20dp"
android:paddingRight="20dp"
>


<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4"
android:orientation="vertical"
android:background="@drawable/cart_custom_background"
android:paddingBottom="2dp"
>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="4"
android:orientation="horizontal"
android:layout_marginRight="1dp"
android:layout_marginLeft="1dp"
>

Answer

Now i need to add a background image,So that i need to add a frame layout here.

You don't need to add another layout to give background. Your root (or even any other)<LinearLayout> should be enough. You can set the background using:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/my_drawable" > // Can also give color here

When i change parent Linear Layout to Frame Layout, it disappears all the items in the linear layout.

Thats primarily because the <FrameLayout> unlike <LinearLayout> kept adding all the children on top of each other.