Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiline textview in table row not wrapping properly

I'm trying to get my text of my text view within the table row to appear on more than one line, but for some reason it doesn't wrap properly and I end up with this (see screenshot). I know the text view has something to do this it but I don't know what I causing this problem to occur. What can be done to resolve this issue?

Screenshot

enter image description here enter image description here

List item XML

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TableRow>
        <ImageView
            android:id="@+id/img"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_gravity="center_vertical" />

        <TextView
            android:id="@+id/txt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginStart="15dp"
            android:layout_marginEnd="15dp"
            android:singleLine="false"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    </TableRow>
</TableLayout>
like image 798
wbk727 Avatar asked Aug 13 '15 17:08

wbk727


1 Answers

You need specify android:layout_weight="1".

This value is telling to TableRow that the TextView is need to be equivalent to match_parent

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_width="match_parent"
             android:layout_height="match_parent">
    <TableRow
            >
        <ImageView
                android:id="@+id/img"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_gravity="center_vertical"/>

        <TextView
                android:id="@+id/txt"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginStart="15dp"
                android:layout_marginEnd="15dp"
                android:layout_weight="1"
                android:text="This is a long long long long text fodshfkjsdkjfjsh js hdfjksh kjdhf kjshdkjf"
                android:textAppearance="?android:attr/textAppearanceLarge"/>
    </TableRow>
</TableLayout>

enter image description here

like image 118
Sergey Shustikov Avatar answered Oct 24 '22 09:10

Sergey Shustikov