-1

I have a relative layout with several buttons in it.When auto rotate happens all buttons get overlapped.how can i avoid that so that all the controls remain intact on auto rotate??

Any help would be really appreciated.

Thanks

  • 1
    for that you have to create two layouts for example for layout also create a folder name as layout-land and then set your xml file just remember every id should be same name of the layout buttons id etc should be same in these two folders – Hafiz.M.Usman Nov 26 '14 at 05:48
  • @nDroidDev: I have just a sample layout having multiple buttons..like 6 buttons and an edittext the moment screen is flipped everything gets messd up..its nt letting me post code here.. – Gourav Sharma Nov 26 '14 at 06:00
  • @ Hafiz.M.Usman:Thanx sounds pretty good...could u just show me any examople?? – Gourav Sharma Nov 26 '14 at 06:04
  • @ Hafiz.M.Usman: I have added another folder but everything is getting over lapped..even in layout-land folder – Gourav Sharma Nov 26 '14 at 06:16

2 Answers2

0

you should align view with respect to other views to avoid overlapping .. using android:layout_below, android:layout_toRightOf etc properties..

Something like this..

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

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button1" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/button1"
        android:layout_marginTop="20dp"
        android:text="Button1" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/button2"
        android:layout_marginTop="20dp">

    </EditText>

</RelativeLayout>
iMDroid
  • 2,108
  • 1
  • 16
  • 29
0

you should use some fixed points in your relative view to align your buttons on it, for example if you have four buttons two on top and two below them: and you align the two lower buttons one right_of button 1 and the second at the baseline_end, they will be overlapped in one view or another: it's better to choose to align buttons in the same way :

in this example i will stack the two upper buttons (button 1 and 2) by aligning them on ParentRight and Parentleft as a reference, and the two lower buttons (button 3 and 4) by aligning right and left to buttons 1 and 2 and not by mixing the one to each other:

choose to align all your buttons on fixed points in your layout or all of them relatively to each other (but at least you must have one on a fixed point), and do not align the lowest to a fixed reference in your layout i hope that i clearly explained my answer

M.M.Rame
  • 113
  • 1
  • 9