Friday, 1 June 2012

How to add a background horizontally in vertical linear layout?

There are some contexts in which we have to make such a layout in which the horizontal background is needed on verical layouts, then in this case Frame Layout will come into your help. Just we have to do one thing , to put the given vertical layout in the FrameLayout with an image view added in it.
Let me show you in this example :- 

<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
        
        <FrameLayout  xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        
        <ImageView  android:layout_width="match_parent"
        android:layout_height="20dp"
        android:layout_gravity="bottom"
        android:layout_marginBottom="55dp"
        android:layout_marginLeft="60dp"
        android:background="#D8D8D8"/>

<LinearLayout>

//Your code here for the development of vertical layout on which you want to apply the horizontal background as shown in the figure.

</LinearLayout>
</FrameLayout>
</LinearLayout>