Как обернуть TextView: Android - PullRequest
0 голосов
/ 27 февраля 2020

Two separate textviews

Мой вопрос - это два разных текстовых представления: «Привет» и «Мир». В первом текстовом представлении есть ограничение на число символов 32. Как мне обернуть его содержание, если текст превышает лимит и заставляет «Мир» оставаться в первой строке?

Ниже приведено изображение, показывающее, как оно действует в настоящее время.

enter image description here

Ниже приведен код, который я пытался реализовать. Я пытался написать min_ems , max_ems и ems , но на планшете он выглядит не очень хорошо.

<ImageView
    app:layout_constraintStart_toStartOf="parent"
    android:id="@+id/img_profile"
    android:layout_width="@dimen/image_width"
    android:layout_height="@dimen/image_height"
    android:src="@drawable/active_profile"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintRight_toLeftOf="@id/textView_profile_name"
    tools:ignore="ContentDescription" />

<TextView
    android:id="@+id/textView_profile_name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="@color/dark_gray"
    android:textSize="@dimen/textSize"
    app:layout_constrainedWidth="true"
    android:fontFamily="@font/helvetica_neue_light"
    android:text="Hello"
    app:layout_constraintLeft_toRightOf="@id/img_profile"
  app:layout_constraintRight_toLeftOf="@id/textView_profile_device_count"
    android:maxLines="2"
    android:maxEms="12" **//this code can be a typo I added in stackoverflow**
    android:minEms="2"    **//this code can be a typo I added in stackoverflow**
    app:layout_constraintTop_toTopOf="parent" />

<TextView
    android:id="@+id/textView_profile_device_count"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginEnd="@dimen/dp30"
    android:layout_marginStart="@dimen/dp_5"
    android:singleLine="true"
    app:layout_constrainedWidth="true"
    app:layout_constraintStart_toEndOf="@id/textView_profile_name"
    app:layout_constraintEnd_toStartOf="@id/img_arrow"
    android:textSize="@dimen/textSize"
    app:layout_constraintTop_toTopOf="parent"
    android:maxLines="1"
    android:fontFamily="@font/helvetica_neue_light"
    android:textColor="@color/dark_gray"
    app:layout_constraintBottom_toBottomOf="@id/img_profile"
    android:text="(3 Devices)" />

<ImageView
    tools:ignore="ContentDescription"
    android:id="@+id/img_arrow"
    android:layout_width="@dimen/dp20"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintLeft_toRightOf="@id/textView_profile_device_count"
    app:layout_constraintVertical_weight="1"
    android:layout_height="@dimen/dp20"
    android:src="@drawable/ic_arrow_forward_black_24dp"
    app:layout_constraintEnd_toEndOf="parent"
/>

Ответы [ 2 ]

0 голосов
/ 27 февраля 2020

Если вы хотите, чтобы второй текст показывался только в первой строке, вы можете сделать это

<TextView
    android:id="@+id/textView_profile_name"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:textColor="@color/dark_gray"
    android:textSize="@dimen/textSize"
    app:layout_constrainedWidth="true"
    android:fontFamily="@font/helvetica_neue_light"
    android:maxLines="1"
    android:text="Hello"
    app:layout_constraintStart_toEndOf="@id/img_profile"
    app:layout_constraintEnd_toStartOf="@id/textView_profile_device_count"
    app:layout_constraintTop_toTopOf="parent" />

<TextView
    android:id="@+id/textView_profile_device_count"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginEnd="@dimen/dp30"
    android:layout_marginStart="@dimen/dp_5"
    android:singleLine="true"
    app:layout_constrainedWidth="true"
    app:layout_constraintEnd_toStartOf="@id/img_arrow"
    android:textSize="@dimen/textSize"
    app:layout_constraintTop_toTopOf="parent"
    android:maxLines="1"
    android:fontFamily="@font/helvetica_neue_light"
    android:textColor="@color/dark_gray"
    app:layout_constraintBottom_toBottomOf="@id/img_profile"
    android:text="(3 Devices)" />

При этом ваш второй текст всегда будет оставаться в первой строке. И первая длина текста будет установлена ​​в 0dp, это означает, что первая длина текста будет начинаться с end of img_profile до start of textView_profile_device_count

Но у него все еще могут быть некоторые проблемы, если текст первого текстового просмотра шире, чем ширина текстового просмотра, и это не будет полностью показывать.

PS. Извините за мой плохой Энгли sh.

0 голосов
/ 27 февраля 2020

Используйте android:maxLength="32"

Надеюсь, это поможет.

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