我有這個代碼
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
tools:context=".MainActivity">
<TableRow>
<TextView
android:layout_weight="0.5"
android:text="Login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginStart="50dp"/>
<EditText
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="25dp"
android:layout_marginEnd="25dp"
/>
</TableRow>
<TableRow>
<TextView
android:layout_weight="0.5"
android:text="Email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginStart="50dp"
/>
<EditText
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="25dp"
android:layout_marginEnd="25dp"
/>
</TableRow>
<TableRow>
<Button
android:text="Send"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</TableRow>
它看起來像這個 image1
我需要將此按鈕居中并拉伸到其他表格行的大小,即授權表單的大小。例如,下面的截圖
影像2
我試過了,android:stretchColumns="1"但它不起作用
uj5u.com熱心網友回復:
我查看了您的代碼,并能夠通過以下方式創建您正在尋找的內容
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="*"
android:gravity="center"
tools:context=".MainActivity">
<TableRow>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginLeft="50dp"
android:layout_weight="0.3"
android:text="Login" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="25dp"
android:layout_marginRight="25dp"
android:layout_weight="1" />
</TableRow>
<TableRow>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_weight="0.3"
android:text="Email" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="25dp"
android:layout_marginRight="25dp"
android:layout_weight="1" />
</TableRow>
<TableRow>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="50dp"
android:layout_marginEnd="25dp"
android:text="Send"
android:layout_weight="1"/>
</TableRow>
正如檔案所示,stretchColumns屬性是“要拉伸的列的從零開始的索引”。通過給它值 * 我們說我們希望所有列均勻拉伸。通過調整布局權重,我們可以改變不同視圖的大小。希望這對你有幫助。IMO,您應該考慮將相對或線性布局用于此類相對簡單的 UI,甚至可能是非常寬容的約束布局。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/337085.html
