Размер TextView по размеру текста в нем

Имеется ScrollView, в котором находятся несколько TextView

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginStart="2dp"
    android:layout_marginTop="2dp"
    android:layout_marginEnd="2dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="34dp"
                android:layout_weight="1"
                android:orientation="horizontal">

                <TextView
                    android:id="@+id/text_title_01"
                    android:layout_width="match_parent"
                    android:layout_height="32dp"
                    android:layout_marginStart="8dp"
                    android:layout_marginTop="0dp"
                    android:layout_marginEnd="8dp"
                    android:layout_weight="1"
                    android:inputType="textMultiLine"
                    android:paddingTop="8dp"
                    android:text="@string/txt_title_01"
                    android:textSize="18sp"
                    android:textStyle="bold" />

                <ImageButton
                    android:id="@+id/imageButton"
                    android:layout_width="30dp"
                    android:layout_height="34dp"
                    android:layout_gravity="left"
                    android:layout_marginEnd="8dp"
                    android:layout_marginBottom="0dp"
                    android:layout_weight="1"
                    android:onClick="onClickMenu"
                    app:srcCompat="@drawable/ic_baseline_point" />

            </LinearLayout>

            <TextView
                android:id="@+id/text_small_01"
                android:layout_width="match_parent"
                android:layout_height="54dp"
                android:layout_marginStart="8dp"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="8dp"
                android:text="@string/txt_short_01"
                android:textSize="18sp" />

            <Button
                android:id="@+id/button01"
                android:layout_width="150dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginStart="0dp"
                android:layout_marginTop="0dp"
                android:layout_weight="1"
                android:onClick="onClickShowDetailed01"
                android:text="@string/btn_short_txt" />

        </LinearLayout>


        <LinearLayout
            android:id="@+id/llv_long"
            android:layout_width="match_parent"
            android:layout_height="400dp"
            android:orientation="vertical"
            android:visibility="visible">

            <TextView
                android:id="@+id/text_long"
                android:layout_width="match_parent"
                android:layout_height="350dp"
                android:layout_marginStart="8dp"
                android:layout_marginEnd="8dp"
                android:text="@string/txt_long_01"
                android:textSize="18sp" />

                <LinearLayout
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:orientation="vertical">

                  <Button
                      android:id="@+id/button7"
                      android:layout_width="150dp"
                      android:layout_height="wrap_content"
                      android:layout_gravity="center_horizontal|center_vertical"
                      android:layout_marginEnd="10dp"
                      android:layout_marginRight="10dp"
                      android:gravity="center"
                      android:onClick="onClickCloseDetailed01"
                      android:text="@string/btn_long_txt" />


            </LinearLayout>

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="80dp"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/text_small_02"
                android:layout_width="match_parent"
                android:layout_height="72dp"
                android:layout_marginStart="8dp"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="8dp"
                android:layout_weight="1"
                android:inputType="textMultiLine"
                android:paddingTop="10dp"
                android:text="@string/txt_short_02" />
        </LinearLayout>

    </LinearLayout>

</ScrollView>

Один из TextView (id= text_long) будет содержать большой блок текста, заранее не известный.

Как сделать чтобы размер TextView увеличивался в зависимости от объема текста?

Если установить wrap_content, то он просто занимает все пространство в LinearLayout(id=llv_long), причем перекрывает и тот LinearLayout, что находится внизу. Т.е. размер LinearLayout тоже надо менять.


Ответы (0 шт):