How can I make my listview rows different heights

android, java, listview

Solution

why don't you try making the height = 0dp and weight 1

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:paddingBottom="1dp"
    android:paddingTop="1dp"
    android:paddingLeft="8dp"
    android:paddingRight="8dp" >

    <TextView
        android:id="@+id/user_name"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:maxLines="2"
        android:ellipsize="middle"
        android:textColor="@android:color/holo_blue_dark"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/points"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_gravity="right"
        android:layout_weight="1"
        android:gravity="right"
        android:textStyle="bold" />

</LinearLayout>

update:

check this answer

https://stackoverflow.com/a/7513423/1932105

Problem

Right now if there is a list item that is 2 lines in height then all the rows are two lines in height How can I make the rows' height independent on other rows. ListView ``` <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <ListView android:id="@+id/user_list" android:layout_width="match_parent" android:layout_height="wrap_content" android:divider="@null" /> </LinearLayout> ``` Row ``` <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:paddingBottom="1dp" android:paddingTop="1dp" android:paddingLeft="8dp" android:paddingRight="8dp" > <TextView android:id="@+id/user_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="0" android:maxLines="2" android:ellipsize="middle" android:textColor="@android:color/holo_blue_dark" android:textStyle="bold" /> <TextView android:id="@+id/points" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:layout_weight="1" android:gravity="right" android:textStyle="bold" /> </LinearLayout> ``` I am using a custom adapter extending BaseAdapter. the getView there is nothing special, just a viewholder patern I don't change height or anything

Original source

Related problems