如何改变布局的位置时,在屏幕的Andr​​oid变化的方向? [英] How to change the position of layout when the orientation of screen change in android?

查看:173
本文介绍了如何改变布局的位置时,在屏幕的Andr​​oid变化的方向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何改变布局的位置时,在屏幕的Andr​​oid变化的方向?

我有一个按钮, RelativeLayout的

在手机风景 RelativeLayout的是在底部。

和把它转化为屏幕的右侧,当手机纵向

像下面的图片。

我得到屏幕的方向,但如何从底部设置 RelativeLayout的改变它的位置吧?

----------------------------------编辑------------ ----------------

XML 布局土地code

有两个按钮 top_buttonlayout1 中,另外两个按钮 bottom_buttonlayout1

top_buttonlayout1 相对-2 中的图片,和 bottom_buttonlayout1 是底部 RelativeLayout的

我想将其更改为直,怎么办?

 <?XML版本=1.0编码=UTF-8&GT?;
<的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:baselineAligned =假
    机器人:方向=垂直>
    <的LinearLayout
        机器人:ID =@ + ID / top_buttonlayout1
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentTop =真
        机器人:方向=垂直>        <的LinearLayout
            机器人:ID =@ + ID / top_buttonlayout
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =WRAP_CONTENT
            机器人:方向=横向
            机器人:背景=#00000000>           <的ImageButton
                机器人:ID =@ + ID / SettingButton
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:scaleType =fitXY
                机器人:layout_marginTop =5DP
                机器人:背景=#00000000
                机器人:SRC =@绘制/ parmeter_setting/>            <的ImageButton
                机器人:ID =@ + ID / FileSavebutton
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:scaleType =fitXY
                机器人:layout_marginTop =5DP
                机器人:layout_marginRight =5DP
                机器人:背景=#00000000
                机器人:SRC =@绘制/ save_in_camera/>        < / LinearLayout中>    < / LinearLayout中>    <的LinearLayout
        机器人:ID =@ + ID / bottom_buttonlayout1
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentBottom =真
        机器人:方向=垂直
        机器人:背景=#454749
         >       < RelativeLayout的
            机器人:ID =@ + ID / bottom_buttonlayout
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =match_parent
            机器人:方向=垂直>
            <的ImageButton
                机器人:ID =@ + ID / FileButton
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_marginLeft =20dp
                机器人:scaleType =fitXY
                机器人:layout_centerVertical =真
                机器人:背景=#454749
                机器人:SRC =@绘制/ file_viewer/>             <的ImageButton
                机器人:ID =@ + ID / photo_record_mode
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_marginRight =20dp
                机器人:layout_alignParentRight =真
                机器人:layout_centerVertical =真
                机器人:scaleType =fitXY
                机器人:背景=#454749
                机器人:SRC =@绘制/ recordmode/>        < / RelativeLayout的>
    < / LinearLayout中>< / RelativeLayout的>


解决方案

您必须创建一个XML文件两个版本,并把布局中的端口和布局,土地文件夹内的res文件夹。

例如:

  RES /布局土地[风景模式]
main.xml中
RES /布局端口[人像模式]
main.xml中

您可以进一步参考同在的http://开发商.android.com /培训/基础/​​支持的设备/ screens.html

来源:<一个href=\"http://stackoverflow.com/questions/12781449/different-design-for-landscape-and-portrait-orientation-android\">here

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 ?

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

解决方案

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

这篇关于如何改变布局的位置时,在屏幕的Andr​​oid变化的方向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆