Android:app:layout_constrainedHeight剪切文本视图中的最后一行文本

问题描述 投票:0回答:2

我在ConstraintLayout中有一个带有大文本的TextView,但是最后一行不可见。如果删除app:layoutthen_constrainedHeight,它将变为可见,但TextView会变得与屏幕本身一样高(这就是为什么我首先添加app:layoutthen_constrainedHeight的原因)

有人遇到过这样的问题吗?该怎么办?在下面的示例中,最后一个字符“ 3 4”应位于第二行,但不会显示。屏幕截图:enter image description here

<?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 textview android-constraintlayout
2个回答
0
投票

尝试一下,也许措辞:

android:minLines="2"

因此必须至少为2行


0
投票

如果要这样做,您需要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"
    />
© www.soinside.com 2019 - 2024. All rights reserved.