如何知道设备/仿真器的布局(横向/纵向)被改变 [英] How to know device/emulator layout (landscape/portrait) is changed

查看:136
本文介绍了如何知道设备/仿真器的布局(横向/纵向)被改变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的两个XML布局文件layoutPotrait.xml和layoutLandscape.xml.When设备/仿真器处于纵向模式时,我想设定layoutPortrait.xml文件的内容视图,当我将模拟器改变为横向模式我想设置与layoutLandscape.xml文件内容视图。我怎样才能做到这一点?

I am using two xml layout file layoutPotrait.xml and layoutLandscape.xml.When device/emulator is in portrait mode i want to set the content view with layoutPortrait.xml file and when I will change the emulator to landscape mode I want to set content view with layoutLandscape.xml file. How can I achieve this?

推荐答案

您不需要知道设备是否改变。只需提供布局文件要在两种方式使用所有的布局。

You don't need to know if the device changed. Just provide to layout files for all layouts you want to use in both ways.

如果您的Andr​​oid设备是在横向模式下,你正在加载的布局,如果这个布局文件在/ RES /布局土地文件夹中存在的android系统的外观。如果没有此文件夹中存在,就会从正常/ RES /布局文件夹中加载的布局。

If your Android device is in landscape mode and you are loading a layout the android system will look if this layout file exists in the /res/layout-land folder. If it does not exist in this folder it will load the layout from the normal /res/layout folder.

刚刚命名的文件相同,并把那在A / RES /布局/土地文件夹,名为layoutPortrait.xml在你的/ RES /布局文件夹和layoutLandscape.xml文件。如果该文件夹不存在,创建它。

Just name the files the same and put the file that was called layoutPortrait.xml in your /res/layout folder and the layoutLandscape.xml in a /res/layout/land folder. If the folder does not exist create it.

这篇关于如何知道设备/仿真器的布局(横向/纵向)被改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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