Expand TextView with wrap_content until the neighbor view reaches the end of the parent

后端 未结 7 654
遇见更好的自我
遇见更好的自我 2020-12-13 14:26

I need to achieve the following layout:

\"enter

I have two TextViews in a rela

相关标签:
7条回答
  • 2020-12-13 14:55

    You can archive this layout by TableLayout and shrinkColumns attribute.

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
        <!-- Row 1 -->
        <TableLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:shrinkColumns="0">
    
            <TableRow
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center_vertical">
    
                <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:padding="4dp"
                        android:maxLines="1"
                        android:ellipsize="end"
                        android:text="abcdefghijklmnopqrstuvwxyz"/>
    
                <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:padding="4dp"
                        android:maxLines="1"
                        android:ellipsize="none"
                        android:text="rightText"/>
            </TableRow>
    
        </TableLayout>
    
    
        <!-- Row 2 -->
        <TableLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:shrinkColumns="0">
    
            <TableRow
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center_vertical">
    
                <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:padding="4dp"
                        android:maxLines="1"
                        android:ellipsize="end"
                        android:text="Longer Text view abcdefghijklmnopqrstuvwxyz"/>
    
                <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:padding="4dp"
                        android:maxLines="1"
                        android:ellipsize="none"
                        android:text="rightText"/>
            </TableRow>
    
        </TableLayout>
    
        <!-- Row 3 -->
        <TableLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:shrinkColumns="0">
    
            <TableRow
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center_vertical">
    
                <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:padding="4dp"
                        android:maxLines="1"
                        android:ellipsize="end"
                        android:text="Text view that is very logn and will not fit the parent width abcdefghijklmnopqrstuvwxyz"/>
    
                <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:padding="4dp"
                        android:maxLines="1"
                        android:ellipsize="none"
                        android:text="rightText"/>
            </TableRow>
    
        </TableLayout>
    
    </LinearLayout>
    

    Here is same question ;)

    0 讨论(0)
提交回复
热议问题