2

Hi I am having problem with android relative layout design. I just cant get it to put 4 buttons around one centered button. See XML below as an example. Controls are pretty much self explanatory.

Thank you all for help.

Layout 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>

2 Answers 2

0

Dont use gravity of the relativelayout Instead use this for center ImageButton

android:centerInParent = "true"

I hope it will work

1
  • It works for central button but if i put top button to be above central button it doesn't move. <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" />
    – Damir
    Dec 13, 2012 at 10:35
0

try setting this:

android:layout_centerHorizontal="true" android:layout_centerVertical="true"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.