Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the position of layout when the orientation of screen change in android?

How to change the position of layout when the orientation of screen change in android ?

I have a button in the Relativelayout.

When the phone is LANDSCAPE, the Relativelayout is at the bottom.

And it turn to the right of screen , when phone is PORTRAIT.

It like the following picture.

I get the orientation of screen , but how to setting the Relativelayout change it position from bottom to right ?

enter image description here

----------------------------------EDIT----------------------------

The code of xml in layout-land.

There are two button in top_buttonlayout1 ,the another two button is in bottom_buttonlayout1.

The top_buttonlayout1 is the Relative-2 in the picture , and the bottom_buttonlayout1 is the bottom relativelayout.

And I want it change to straight , how to do ?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:baselineAligned="false"
    android:orientation="vertical" >


    <LinearLayout
        android:id="@+id/top_buttonlayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:orientation="vertical" >

        <LinearLayout
            android:id="@+id/top_buttonlayout"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:background="#00000000" >

           <ImageButton
                android:id="@+id/SettingButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:scaleType="fitXY"
                android:layout_marginTop="5dp"
                android:background="#00000000"
                android:src="@drawable/parmeter_setting" />

            <ImageButton
                android:id="@+id/FileSavebutton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:scaleType="fitXY"
                android:layout_marginTop="5dp"
                android:layout_marginRight="5dp"  
                android:background="#00000000"        
                android:src="@drawable/save_in_camera" />

        </LinearLayout>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/bottom_buttonlayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="vertical"
        android:background="#454749"
         >

       <RelativeLayout
            android:id="@+id/bottom_buttonlayout"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">


            <ImageButton
                android:id="@+id/FileButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:scaleType="fitXY"
                android:layout_centerVertical="true"
                android:background="#454749"
                android:src="@drawable/file_viewer"/>

             <ImageButton
                android:id="@+id/photo_record_mode"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="20dp"
                android:layout_alignParentRight="true"  
                android:layout_centerVertical="true"            
                android:scaleType="fitXY"
                android:background="#454749"
                android:src="@drawable/recordmode"/>

        </RelativeLayout>
    </LinearLayout>

</RelativeLayout>
like image 282
Martin Avatar asked Jan 20 '14 06:01

Martin


2 Answers

You will have to create two versions of xml files and put in layout-port and layout-land folder inside res folder.

eg :

res/layout-land [Landscape Mode]
main.xml 
res/layout-port [Portrait Mode ]
main.xml

You can refer further more on the same at http://developer.android.com/training/basics/supporting-devices/screens.html

source : here

like image 148
Jigar Pandya Avatar answered Oct 27 '22 17:10

Jigar Pandya


Create different layout for lanscape and put it under same name in layout-land folder

like image 44
Androider Avatar answered Oct 27 '22 16:10

Androider