如何将2个TextView与动态文本相互叠加,以便TextView的宽度自动更改以最小化两个TextView的高度?因此具有较大文本的TextView应该更宽,并且两个TextView(行数)的高度应该相同。
这里使用此代码。 文本视图的高度将相同,文本视图的宽度越多,文本占用的空间越大
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:weightSum="2"
android:layout_height="wrap_content">
<TextView
android:layout_weight="1"
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:text="TextView"/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_weight="1"
android:text="TextView"/>
</LinearLayout>