对方向变化急剧布局变化

对方向变化急剧布局变化

本文介绍了对方向变化急剧布局变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个活动的布局。该布局包含一些图像按钮和文本的意见。现在的问题是,当我设置我的设备肖像,它做工精细,但是当我改变方向,以景观,布局给人意想不到的效果的方向。

I have created a layout for an activity. The layout contains some image buttons and text views. The problem is that when I am setting the orientation of my device to portrait, its working fine, but when I am changing the orientation to landscape, the layout is giving unexpected results.

下面是我的布局文件

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true"
    android:padding="50dp" >


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

    <ImageView
        android:id="@+id/settings_imageView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:src="@android:drawable/bottom_bar" />

    <TextView
        android:id="@+id/settings_textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="16dp"
        android:text="@string/my_settings"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <ImageView
        android:id="@+id/myProgramming_imageView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/settings_imageView"
        android:layout_alignParentLeft="true"
        android:src="@android:drawable/bottom_bar" />

    <TextView
        android:id="@+id/myProgramming_textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/myProgramming_imageView"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="14dp"
        android:text="@string/my_programming"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <ImageView
        android:id="@+id/library_imageView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/myProgramming_imageView"
        android:layout_alignParentLeft="true"
        android:src="@android:drawable/bottom_bar" />

    <TextView
        android:id="@+id/library_textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/library_imageView"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="16dp"
        android:text="@string/library"
        android:textAppearance="?android:attr/textAppearanceMedium" />

</RelativeLayout>
</ScrollView>

下面是肖像模式对设备的输出,这是预计在纵向和横向模式的输出:

Here is the output of the portrait mode on device, and this is the output which is expected on both portrait and landscape modes:

下面是在风景 *的的设备模式的*,这是意外的输出:

Here is the output for the landscape *mode on device*, this is unexpected:

我想要的布局看起来一样在纵向和横向模式。

I want the layout to look alike in portrait and landscape modes.

推荐答案

- 看来你屏幕尺寸在这里创建一个问题

- It seems you screen size is creating a problem here.

- 您必须创建 RES 目录布局 - 在另一个文件夹土地,并在其中创建就像你在布局做了一个的.xml 文件文件夹,并使它看起来你想要的方式在横向模式

- You will have to create another folder under res directory as layout-land, and in it create a .xml file just like you did in layout folder, and make it look the way you want it in landscape mode.

- :当你的应用程序进入风景模式,自动的.xml 文件将被选择(即从布局陆)文件夹。

- When your app goes into landscape mode, automatically this .xml file will be selected (ie from the layout-land) folder.

这篇关于对方向变化急剧布局变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 01:44