我是Android新手。我希望把4个按钮水平地等于边缘与左,右侧所示在下面的线框图:在左右两侧放置等边距的按钮Android
我搜索很多谷歌和#2也。我试图设置android:layout_weight =“1”。但它只能从左侧设置相等的余量。我想在两侧和多个屏幕布局上进行设置。我想知道应该为此应用哪些布局和属性。我在Android工作室中使用,主要使用Drag-Drop方法进行设计。
目前我已经XML布局如下:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/frameLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="10dp"
android:id="@+id/relativeLayout">
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
android:id="@+id/b3"
android:layout_gravity="left|center_vertical"
android:onClick="buttonThree"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="false"
android:layout_alignParentStart="true"
android:layout_alignParentRight="false"
android:layout_weight="1"
android:width="0dp" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5"
android:id="@+id/b5"
android:layout_gravity="left|center_vertical"
android:onClick="buttonFive"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/b3"
android:layout_toEndOf="@+id/b3"
android:layout_alignParentRight="false"
android:layout_alignParentLeft="false"
android:layout_weight="1"
android:width="0dp"
android:layout_alignParentBottom="false" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="7"
android:id="@+id/b7"
android:layout_gravity="left|center_vertical"
android:onClick="buttonSeven"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/b5"
android:layout_toEndOf="@+id/b5"
android:layout_alignParentRight="false"
android:layout_weight="1"
android:width="0dp" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="9"
android:id="@+id/b9"
android:layout_gravity="left|center_vertical"
android:onClick="buttonNine"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/b7"
android:layout_toEndOf="@+id/b7"
android:layout_alignParentRight="false"
android:layout_weight="1"
android:width="0dp" />
</RelativeLayout>
看看的'LinearLayout' –
使用'LinearLayout' layout_weight'的'概念代替的RelativeLayout的' ','layout_weight'可以和'LinearL一起使用ayout' –
必须要学习:[Android布局技巧](http://android-developers.blogspot.in/2009/02/android-layout-tricks-1.html) –