table 行中的多行文本视图未正确换行
Multiline textview in table row not wrapping properly
我试图让 table 行中我的文本视图的文本显示在多行中,但由于某种原因它没有正确换行,我最终得到了这个 (见截图)。我知道文本视图可以做到这一点,但我不知道是什么导致了这个问题的发生。可以做些什么来解决这个问题?
截图
列表项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>
简单的解决方法是增加保证金结束,
尝试:
<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" />
您需要指定 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>
赋予<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>
试试下面的代码可能会有帮助
<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" />
我试图让 table 行中我的文本视图的文本显示在多行中,但由于某种原因它没有正确换行,我最终得到了这个 (见截图)。我知道文本视图可以做到这一点,但我不知道是什么导致了这个问题的发生。可以做些什么来解决这个问题?
截图
列表项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>
简单的解决方法是增加保证金结束, 尝试:
<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" />
您需要指定 android:layout_weight="1"
。
This value is telling to
TableRow
that theTextView
is need to be equivalent tomatch_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>
赋予<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>
试试下面的代码可能会有帮助
<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" />