代码之家  ›  专栏  ›  技术社区  ›  wbk727

表行中的多行文本视图未正确换行

  •  9
  • wbk727  · 技术社区  · 9 年前

    我试图让表行中文本视图的文本显示在多行上,但由于某些原因,它没有正确换行,我最终得到了这个结果(见屏幕截图)。我知道文本视图与此有关,但我不知道是什么导致了这个问题的发生。可以做什么来解决这个问题?

    截图

    enter image description here enter image description here

    列表项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>
    
    4 回复  |  直到 9 年前
        1
  •  37
  •   Sergey Shustikov    6 年前

    您需要指定 android:layout_weight="1" .

    这个值告诉我们 TableRow TextView 需要等于 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

        2
  •  0
  •   Rustam    9 年前

    <TableRow> 属性

       <TableRow
           android:layout_width="wrap_content"
            android:layout_height="wrap_content">
            <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:paddingRight="10dip"
                android:textAppearance="?android:attr/textAppearanceLarge" />
        </TableRow>
    
        3
  •  0
  •   Nikul Rao    9 年前

    尝试以下代码可能会有所帮助

    <com.project_name.JustifiedTextView.JustifiedTextView
                        android:id="@+id/txtHide"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="right"
                        android:padding="25dp"
                        xmlns:noghteh="http://noghteh.ir" 
                        android:text="" 
                        android:textColor="@color/BlueText"
                        android:textSize="@dimen/text_size" />
    

    链接: https://github.com/navabi/JustifiedTextView

        4
  •  -1
  •   Marcin D    9 年前

    简单的解决方案是增加边缘端, 尝试:

    <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="30dp"
            android:singleLine="false"
            android:textAppearance="?android:attr/textAppearanceLarge" />