SoulRayder SoulRayder - 11 days ago 7
Android Question

Setting a row of images in the bottom-right corner of a listview item

I have a custom listview in which I want to place four images in the bottom right corner of each item of a scrollable listview.

However with my current XML, the imageview array is showing at the top-right instead of the bottom-right of each element of the listview. As per my knowledge, I am using the right attributes, but still getting this misplaced output. Any help would be greatly appreciated. TIA.

enter image description here

Layout XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >

<ImageView
android:id="@+id/id1"
android:layout_width="85dp"
android:layout_height="85dp"
android:padding="10dp"
android:scaleType="centerCrop" />


<TextView
android:id="@+id/id2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="@android:style/TextAppearance.Medium"
android:textStyle="bold"
android:textColor="@color/colorPrimaryDark"
android:layout_toRightOf="@id/id1"
/>

<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="right|bottom" >

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/id3"
android:background="@drawable/img1"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/id3"
android:id="@+id/id4"
android:background="@drawable/img2"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/id4"
android:id="@+id/id5"
android:background="@drawable/img3"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/id5"
android:id="@+id/id6"
android:background="@drawable/img4"/>





Answer

Try setting layout_height of LinearLayout as wrap_content and set layout_alignParentBottom to true.

<?xml version="1.0" encoding="utf-8"?><?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="wrap_content">

    <ImageView
        android:id="@+id/id1"
        android:layout_width="85dp"
        android:layout_height="85dp"
        android:padding="10dp"
        android:scaleType="centerCrop" />

    <TextView
        android:id="@+id/id2"
        style="@android:style/TextAppearance.Medium"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/id1"
        android:textStyle="bold" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:gravity="right|bottom"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/id3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/img1" />

        <ImageView
            android:id="@+id/id4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toLeftOf="@id/id3"
            android:src="@drawable/img2" />

        <ImageView
            android:id="@+id/id5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toLeftOf="@id/id4"
            android:src="@drawable/img3" />

        <ImageView
            android:id="@+id/id6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toLeftOf="@id/id5"
            android:src="@drawable/img4" />
    </LinearLayout>

</RelativeLayout>
Comments