Android: app:layout_constrainedHeight 剪切文本视图中的最后一行文本
Android: app:layout_constrainedHeight cuts last line of text in the text view
我在 ConstraintLayout 中有一个带有大文本的 TextView,但最后一行不可见。如果我删除 app:layoutthen_constrainedHeight
它变得可见,但 TextView 变得和屏幕本身一样高(这就是我首先添加 app:layoutthen_constrainedHeight
的原因)
有人遇到过这样的问题吗?可以用它做什么?在下面的示例中,最后一个字符“3 4”应该在第二行,但它们没有显示。
截屏:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<ImageView
android:id="@+id/image_1"
android:layout_width="20dp"
android:layout_height="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:contentDescription="@null"
android:background="@color/red"
/>
<TextView
android:id="@+id/text_1"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constrainedHeight="true"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toRightOf="@+id/image_1"
app:layout_constraintRight_toLeftOf="@+id/image_2"
app:layout_constraintBottom_toTopOf="@+id/text_2"
tools:text="1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4"
/>
<TextView
android:id="@+id/text_2"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constrainedHeight="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@+id/image_1"
app:layout_constraintRight_toLeftOf="@+id/image_2"
app:layout_constraintTop_toBottomOf="@+id/text_1"
tools:text="end"
/>
<ImageView
android:id="@+id/image_2"
android:layout_width="20dp"
android:layout_height="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:background="@color/red"
android:contentDescription="@null"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
试试这个,也许措辞:
android:minLines="2"
所以它被强制至少为 2 行
如果你想这样做,你需要 layout_height 一个值,因为它太长了,所以你需要更具体:
<TextView
android:id="@+id/text_1"
android:layout_width="0dp"
android:layout_height="100dp"
app:layout_constrainedHeight="true"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toRightOf="@+id/image_1"
app:layout_constraintRight_toLeftOf="@+id/image_2"
app:layout_constraintBottom_toTopOf="@+id/text_2"
tools:text="1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
6"
/>
这是 ConstraintLayout 版本 1.1.3 到 2.0.0-beta1 中的错误
这是行李追踪器中的任务 https://issuetracker.google.com/issues/132314169
它将在 2.0.0-beta2 中修复
我在 ConstraintLayout 中有一个带有大文本的 TextView,但最后一行不可见。如果我删除 app:layoutthen_constrainedHeight
它变得可见,但 TextView 变得和屏幕本身一样高(这就是我首先添加 app:layoutthen_constrainedHeight
的原因)
有人遇到过这样的问题吗?可以用它做什么?在下面的示例中,最后一个字符“3 4”应该在第二行,但它们没有显示。
截屏:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<ImageView
android:id="@+id/image_1"
android:layout_width="20dp"
android:layout_height="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:contentDescription="@null"
android:background="@color/red"
/>
<TextView
android:id="@+id/text_1"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constrainedHeight="true"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toRightOf="@+id/image_1"
app:layout_constraintRight_toLeftOf="@+id/image_2"
app:layout_constraintBottom_toTopOf="@+id/text_2"
tools:text="1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4"
/>
<TextView
android:id="@+id/text_2"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constrainedHeight="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@+id/image_1"
app:layout_constraintRight_toLeftOf="@+id/image_2"
app:layout_constraintTop_toBottomOf="@+id/text_1"
tools:text="end"
/>
<ImageView
android:id="@+id/image_2"
android:layout_width="20dp"
android:layout_height="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:background="@color/red"
android:contentDescription="@null"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
试试这个,也许措辞:
android:minLines="2"
所以它被强制至少为 2 行
如果你想这样做,你需要 layout_height 一个值,因为它太长了,所以你需要更具体:
<TextView
android:id="@+id/text_1"
android:layout_width="0dp"
android:layout_height="100dp"
app:layout_constrainedHeight="true"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toRightOf="@+id/image_1"
app:layout_constraintRight_toLeftOf="@+id/image_2"
app:layout_constraintBottom_toTopOf="@+id/text_2"
tools:text="1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
6"
/>
这是 ConstraintLayout 版本 1.1.3 到 2.0.0-beta1 中的错误 这是行李追踪器中的任务 https://issuetracker.google.com/issues/132314169
它将在 2.0.0-beta2 中修复