简体   繁体   English

相对布局顶部和底部对齐

[英]Relativelayout align top and bottom

I would like to align center horizontial & center vertical all 3 buttons as 1 button in my relativelayout! 我想在我的相对布局中将所有3个按钮的中心水平和垂直中心对齐为1个按钮!

I used LinearLayout with parameter android:layout_weight, but Buttons's height is modified. 我将LinearLayout与参数android:layout_weight一起使用,但Buttons的高度已修改。 This is my layout file. 这是我的布局文件。 Thanks! 谢谢!

<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=".Main" >

<Button
    android:id="@+id/bt_singleColor"
    android:layout_width="150dp"
    android:layout_height="100dp"
    android:layout_centerHorizontal="true"
    android:layout_margin="@dimen/button_margin"
    android:background="@drawable/button_circle"
    android:padding="@dimen/button_padding"
    android:text="@string/button_01"
    android:textColor="@color/button_text_color" />

<Button
    android:id="@+id/bt_shake"
    android:layout_width="150dp"
    android:layout_height="100dp"
    android:layout_below="@+id/bt_singleColor"
    android:layout_centerHorizontal="true"
    android:layout_margin="@dimen/button_margin"
    android:background="@drawable/button_circle"
    android:padding="@dimen/button_padding"
    android:text="@string/button_02"
    android:textColor="@color/button_text_color" />

<Button
    android:id="@+id/bt_autoColor"
    android:layout_width="150dp"
    android:layout_height="100dp"
    android:layout_below="@+id/bt_shake"
    android:layout_centerHorizontal="true"
    android:layout_margin="@dimen/button_margin"
    android:background="@drawable/button_circle"
    android:padding="@dimen/button_padding"
    android:text="@string/button_03"
    android:textColor="@color/button_text_color" />

You can use something like 您可以使用类似

<RelativeLayout to match parent or fill parent>
<LinearLayout with wrap_content and layout centerInParent>
<Button/>
<Button/>
<Button/>
</LinearLayout>
</RelativeLayout>

meaning that the LinearLayout is centered absolutely in the Relative layout and you can play with this alignment if you want something else. 表示LinearLayout绝对位于相对布局的中心,如果需要其他功能,则可以使用此路线。 While for the Linearlayout you have wrap_content to detect its size based on the buttons size, margin and padding. 对于Linearlayout,您可以使用wrap_content来根据按钮的大小,边距和填充来检测其大小。 Also don't forget about orientation for LinearLayout. 另外,不要忘了LinearLayout的方向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM