4
在android中,我应该如何将2个按钮放在一行中具有相同的宽度和高度?我应该使用哪种布局?在android中,我应该如何将2个按钮放在一行中具有相同的宽度和高度?
在android中,我应该如何将2个按钮放在一行中具有相同的宽度和高度?我应该使用哪种布局?在android中,我应该如何将2个按钮放在一行中具有相同的宽度和高度?
layout_weight负责设置相同或不同比例的组件。
使用:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
>
<Button android:text="@+id/Button01" android:id="@+id/Button01"
android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text="@+id/Button02" android:id="@+id/Button02"
android:layout_weight="1" android:layout_width="wrap_content"
android:layout_height="wrap_content"></Button>
</LinearLayout>
您可以在多行使用RelativeLayout的认沽多个按钮:为解决
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginLeft="22dp"
android:layout_marginTop="43dp"
android:text="Button" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button1"
android:layout_alignBottom="@+id/button1"
android:layout_alignParentRight="true"
android:layout_marginRight="36dp"
android:text="Button" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/button1"
android:layout_below="@+id/button1"
android:layout_marginTop="56dp"
android:text="Button" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button3"
android:layout_alignBottom="@+id/button3"
android:layout_alignRight="@+id/button2"
android:text="Button" />
</RelativeLayout>
如果您的问题得到解决,那么请记住这职位 – 2011-03-26 11:05:28