Использование wrap_content без вывода содержимого на экран и без использования layout_weight - PullRequest
1 голос
/ 28 мая 2020

Итак, у меня есть что-то вроде этого:

LinearLayout:
   LinearLayout - wrap_content, background black:
      TextView - wrap_content
   LinearLayout:
      Image - 20dp
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clickable="true"
    android:focusable="true"
    android:gravity="center|start"
    android:padding="5dp"
    android:layout_margin="2dp">


    <TextView
        android:id="@+id/message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="klgjdkljgilfdjgidfhjiogjdio;jhgiju;fgjdhjgu;hdfuighdfuk;ghduk;fhgukldhfgujkdfhyufhglfdhguldfhguklhfdulghldfughyulfhdulghdfulghul"
        android:textColor="#D5D5D5" />

    <LinearLayout
        android:layout_width="15dp"
        android:layout_gravity="center"
        android:gravity="center"
        android:layout_marginBottom="2dp"
        android:layout_height="match_parent">

        <ImageView
            android:layout_width="10dp"
            android:layout_height="10dp"
            android:layout_gravity="bottom|center"
            android:src="@drawable/edit" />
    </LinearLayout>
</LinearLayout>

Это отлично работает, но когда TextView содержит текст, размер которого превышает размер экрана, изображение выходит за пределы экрана. Я не хочу, чтобы это произошло.

Вот пример:

Example Кто-нибудь знает, как это исправить, чтобы не go снаружи экран?

enter image description here

Спасибо!

1 Ответ

1 голос
/ 28 мая 2020

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

<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="match_parent">

    <TextView
        android:id="@+id/message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="klgjdkljgilfdjgidfhjiogjdio;jhgiju;fgjdhjgu;hdfuighdfuk;ghduk;fhgukldhfgujkdfhyufhglfdhguldfhguklhfdulghldfughyulfhdulghdfulghul"
        android:textColor="#D5D5D5"
        app:layout_constrainedWidth="true"
        app:layout_constraintEnd_toStartOf="@id/image"
        app:layout_constraintHorizontal_bias="0"
        app:layout_constraintHorizontal_chainStyle="packed"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>


    <ImageView
        android:id="@+id/image"
        android:layout_width="20dp"
        android:layout_height="10dp"
        android:layout_gravity="bottom|center"
        android:src="@drawable/edit"
        app:layout_constrainedWidth="true"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@id/message"
        app:layout_constraintTop_toTopOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>
...