[英]Android layout: How to put 2 TextViews next to each other with minimum space
如何將兩個帶有動態文本的TextView彼此放在一起,以使TextView的寬度自動更改以最小化兩個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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.