我把4个按钮放在相对布局中.我希望它们具有相同的宽度,并修复手机的任何屏幕尺寸.我的代码如下:
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="38dp" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Button" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/button1"
android:text="Button" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/button2"
android:text="Button" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/button3"
android:text="Button" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我应该修改什么?
Dan*_*n S 15
切换到LinearLayout并为所有按钮赋予相同的权重.
例如:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="38dp"
android:orientation="horizontal">
<Button android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
<Button android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
<Button android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10425 次 |
| 最近记录: |