2

嗨,我遇到了 android 相对布局设计的问题。我只是无法将 4 个按钮放在一个居中的按钮周围。请参阅下面的 XML 作为示例。控件几乎是不言自明的。

谢谢大家的帮助。

布局 XML

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_test_wholeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:gravity="center_horizontal"
android:orientation="vertical" >

<RelativeLayout
    android:id="@+id/main_test_relativeLayoutMenu"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:background="@drawable/main_panel_a"
    android:gravity="center" >

    <ImageButton
        android:id="@+id/center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/more_baby_call" />

    <ImageButton
        android:id="@+id/top"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/center"
        android:src="@drawable/more_baby_call" />

    <ImageButton
        android:id="@+id/bottom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/center"
        android:src="@drawable/more_baby_call" />

    <ImageButton
        android:id="@+id/right"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/center"
        android:src="@drawable/more_baby_call" />

    <ImageButton
        android:id="@+id/left"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@+id/center"
        android:src="@drawable/more_baby_call" />

</RelativeLayout>

</RelativeLayout>

4

2 回答 2

0

尝试设置:

android:layout_centerHorizo​​ntal="true" android:layout_centerVertical="true"

于 2013-11-26T12:00:34.307 回答
0

不要使用相对布局的重力而是将其用于中心 ImageButton

android:centerInParent = "true"

我希望它会工作

于 2012-12-08T01:38:14.820 回答