Search code examples
androidandroid-layoutlistviewandroid-imageviewandroid-custom-view

Inflate drawable out of the layout


I have a layout defining item of listview. I need to have it as follows:

enter image description here

I need that red rectangle (ImageView) to overlays over two LinearLayouts (see the image I've uploaded).

My current list item layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/background"
    android:paddingLeft="15dip"
    android:paddingRight="15dip" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/item_rounded"
        android:padding="15dip" >
    <TextView
            android:id="@+id/text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Item 1"
            android:textSize="16sp" />
    </LinearLayout>
</LinearLayout>

Solution

  • Try this layout:

    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/background"
            android:paddingLeft="15dip"
            android:paddingRight="15dip" >
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/item_rounded"
                android:padding="15dip" >
    
                <TextView
                    android:id="@+id/text"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Item 1"
                    android:textSize="16sp" />
            </LinearLayout>
        </LinearLayout>
    
        <ImageView
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:background="#FF0000" />
    </RelativeLayout>