Search code examples
androidandroid-layoutandroid-listview

CustomListViewAdapter Layout automatically adjust to multiline if the elements would go out of screen?


I am building an Android Application and I am displaying information in a CustomListView. I already have the whole thing working, from the ListView layout and adapter, as well as the custom objects needed.

My customListView layout file has 6 textViews inside as such:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="5dp">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:textSize="12dp"
        android:text="Large Text"
        android:id="@+id/id1"
        android:gravity="center_vertical|center_horizontal"
        android:layout_marginLeft="2pt"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:textSize="15dp"
        android:text="Large Text"
        android:id="@+id/id2"
        android:gravity="center_vertical|center_horizontal"
        android:layout_marginLeft="2pt"
        android:textStyle="bold"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:textSize="15dp"
        android:text="Large Text"
        android:id="@+id/id3"
        android:gravity="center_vertical|center_horizontal"
        android:layout_marginLeft="2pt"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:textSize="15dp"
        android:text="Large Text"
        android:id="@+id/id4"
        android:gravity="center_vertical|center_horizontal"
        android:layout_marginLeft="2pt"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="15dp"
        android:text="Large Text"
        android:id="@+id/id5"
        android:gravity="center_vertical|center_horizontal"
        android:layout_marginLeft="2pt"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:textSize="15dp"
        android:text="Large Text"
        android:id="@+id/id6"
        android:gravity="center_vertical|center_horizontal"
        android:layout_marginLeft="2pt"/>

</LinearLayout>

However, what happens is if one of those fields have lengthy input, say for example ids3-4, the textViews id5 and id6 tends to be "cut off" because they are out of screen bounds already.

I want to be change the layout in such a way that whenever any textViews goes out of the screen, they just go to the next line.

How can I do this?


Solution

  • ApmeM's FlowLayout does exactly what you're describing.