![](/img/trans.png)
[英]Align the top of a View to the bottom of another view in a RelativeLayout
[英]Relativelayout align top and bottom
我想在我的相對布局中將所有3個按鈕的中心水平和垂直中心對齊為1個按鈕!
我將LinearLayout與參數android:layout_weight一起使用,但Buttons的高度已修改。 這是我的布局文件。 謝謝!
<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" />
您可以使用類似
<RelativeLayout to match parent or fill parent>
<LinearLayout with wrap_content and layout centerInParent>
<Button/>
<Button/>
<Button/>
</LinearLayout>
</RelativeLayout>
表示LinearLayout絕對位於相對布局的中心,如果需要其他功能,則可以使用此路線。 對於Linearlayout,您可以使用wrap_content來根據按鈕的大小,邊距和填充來檢測其大小。 另外,不要忘了LinearLayout的方向。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.