【发布时间】:2018-12-21 14:32:39
【问题描述】:
我有一个 TableLayout,其中每个 TableRow 包含一个 ImageView 和一个 TextView。如果它们的内容不适合一行,我想让 TextViews 扩展到多行。
我尝试了许多不同的属性设置,例如将 TextView 设置为 wrap_content、maxLines、scrollHorizontal = false,并且没有省略号。我也尝试将 TableView 设置为 wrap_content 但没有运气。我在网上能找到的一切似乎都是关于没有嵌套在 TableLayout 中的 TextView,所以我不知道 TableLayout 设置是否会干扰其他答案。我能找到的最接近的相关问题是here,但它对我不起作用。
下面是我的 TableLayout 的 XML:
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:gravity="center_vertical|start"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp">
<ImageView
android:id="@+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.15"
app:srcCompat="@drawable/ic_info_24px" />
<TextView
android:id="@+id/AdditionalInfo"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_span="3"
android:layout_weight="0.85"
android:gravity="center_vertical|start"
android:text="Additional Info that can potentially be too much for one line"
android:textSize="16sp" />
</TableRow>
</TableLayout>
【问题讨论】: