更改布局时更改XML布局 [英] Xml layout changes while changing orientation

查看:84
本文介绍了更改布局时更改XML布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个活动会打开,具体取决于SD卡的存在.一个活动具有三个ButtonsTextView,另一个活动具有ImageView,按钮和缩放控件.当我改变方向时,按钮在水平方向上会变得混乱.如何解决这个问题?

I have two activities which opens depending on the SD card presence. One activity has three Buttons and a TextView and the other an ImageView, a button and zoom control. When I change the orientation, the buttons get scrambled around while in horizontal direction. How to go around this?

我的"SD"卡布局

My 'SD' card layout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#1E1E1E"
    android:orientation="vertical" >

    <Button
        android:id="@+id/button_print"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="44dp"
        android:background="@drawable/my_button"
        android:text="@string/print" />

    <TextView
        android:id="@+id/text_SDmissing"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="80dp"
        android:text="@string/SDmissing"
        android:textSize="20dp" />

    <Button
        android:id="@+id/button_camera"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/button_print"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="58dp"
        android:background="@drawable/my_button"
        android:text="@string/camera" />

    <Button
        android:id="@+id/button_insert"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/text_SDmissing"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="40dp"
        android:background="@drawable/my_button"
        android:text="@string/insert" />

</RelativeLayout>

推荐答案

您必须为纵向和横向模式创建单独的XML文件,并将其放置在不同的目录中.设备将自动选择正确的设备.您可以使用以下目录结构

You have to create separate XML files for portrait and landscape modes and place it in different directories. The device will automatically select the right one. You can use the following directory structure

res/layout/my_layout.xml   
res/layout-land/layout.xml

有关更多参考,您可以检查: http://developer.android.com/guide/practices/screens_support.html

For further reference you can check: http://developer.android.com/guide/practices/screens_support.html

这篇关于更改布局时更改XML布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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