我有兩個 TextView(tv1和tv2),我希望tv2位于tv1的右側,如下所示:

uj5u.com熱心網友回復:
試試這個對我有用。您必須在兩個 TextView 中設定 layout_width="0dp" 和 layout_weight="1"。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@ id/tv1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="20dp"
android:text="hello world ********** welcome"/>
<TextView
android:id="@ id/tv2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="20dp"
android:text="hello world ********** welcome" />
</LinearLayout>
uj5u.com熱心網友回復:
終于找到了一個完美的存檔方式:
更改
LinearLayout至TableLayoutTableRow使用
shrinkColumnsof 屬性TableLayout指定要收縮的列的從零開始的索引。我將它設定為0因為我希望tv1是可收縮的,這樣它就不會占用所有空間<TableLayout 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="wrap_content"> <TableRow android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:id="@ id/tv1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@ id/tv2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="*" /> </TableRow> </TableLayout>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/326263.html
