ConstraintLayout не размечает длинный текст в TextView - PullRequest
0 голосов
/ 26 апреля 2018

У меня есть TextView справа от изображения.Я пытаюсь поместить длинный текст рядом с изображением, но этот текст должен автоматически заканчиваться добавлением «...» в конце.Однако это не работает.Я использую этот макет:

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginTop="8dp">

<ImageView
    android:id="@+id/file_icon"
    android:layout_width="250px"
    android:layout_height="250px"
    android:layout_gravity="center"
    android:clickable="true"
    android:scaleType="centerInside"
    android:src="@drawable/ic_launcher"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<TextView
    android:id="@+id/file_title"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:ellipsize="end"
    android:maxLines="1"
    android:text="This is a very long title and I hope I have the dots to break it"
    android:textAppearance="@style/TextAppearance.AppCompat.Medium"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBottom_toTopOf="@+id/file_type"
    app:layout_constraintVertical_chainStyle="packed"
    app:layout_constraintStart_toEndOf="@+id/file_icon"
    app:layout_constraintWidth_default="wrap"/>

<TextView
    android:id="@+id/file_type"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="8dp"
    android:text="Type"
    android:textAppearance="@style/TextAppearance.AppCompat.Small"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/file_title"
    app:layout_constraintLeft_toRightOf="@+id/file_icon" />

<ImageView
    android:id="@+id/file_download"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:layout_gravity="center"
    android:clickable="true"
    android:scaleType="centerInside"
    android:src="@drawable/ic_action_download"
    app:layout_constraintTop_toBottomOf="@+id/file_title"
    app:layout_constraintRight_toRightOf="parent" />

Результат таков:

enter image description here

Почему долготекст не эллипсоидный, такой, что "..." появляется в конце?Я прочитал этот и этот пост, но он не работает для меня.Может ли кто-нибудь помочь мне здесь?

Ответы [ 2 ]

0 голосов
/ 02 июля 2018

Я часто сталкивался с той же проблемой, но по другой причине.Очевидно, когда вы используете ellipsize, вы должны использовать android:layout_width="0dp" для TextView.Я часто ошибочно использовал android:layout_width="wrap_content".Тот, кто опубликовал исходную проблему, не допустил этой ошибки, но я отмечаю, что это может быть еще одной причиной того, что «ConstraintLayout не преобразует длинный текст в TextView».

0 голосов
/ 26 апреля 2018

Используйте app:layout_constraintEnd_toEndOf="parent" для вашего file_title TextView

Попробуйте это

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginTop="8dp">

    <ImageView
        android:id="@+id/file_icon"
        android:layout_width="250px"
        android:layout_height="250px"
        android:layout_gravity="center"
        android:clickable="true"
        android:scaleType="centerInside"
        android:src="@drawable/abc"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/file_title"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:maxLines="1"
        android:text="This is a very long title and I hope I have the dots to break it"
        android:textAppearance="@style/TextAppearance.AppCompat.Medium"
        app:layout_constraintBottom_toTopOf="@+id/file_type"
        app:layout_constraintStart_toEndOf="@+id/file_icon"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_chainStyle="packed"
        app:layout_constraintEnd_toEndOf="parent"

        />

    <TextView
        android:id="@+id/file_type"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:text="Type"
        android:textAppearance="@style/TextAppearance.AppCompat.Small"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toRightOf="@+id/file_icon"
        app:layout_constraintTop_toBottomOf="@+id/file_title" />

    <ImageView
        android:id="@+id/file_download"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_gravity="center"
        android:clickable="true"
        android:scaleType="centerInside"
        android:src="@drawable/abc"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/file_title" />

</android.support.constraint.ConstraintLayout>

ВЫХОД

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...