简体   繁体   English

当我的Android平板电脑应用在风景Mdoe中的手机上运行时,如何使其外观相同

[英]How can I make my android tablet app to look the same when it runs on phone in landscape mdoe

I have a android app layout for tablet. 我有平板电脑的android应用程序布局。 Its layout is 'landscape' based (ie it looks the way i want when I run on tablet (by default landscape). 它的布局基于“横向”(即,当我在平板电脑上运行时,它看起来像我想要的样子(默认为横向)。

But when I run the same app on a phone, android runs in portrait mode, (it squeeze my 'landscape' layout into a portrait ). 但是,当我在手机上运行相同的应用程序时,android在纵向模式下运行((将我的“横向”布局压缩为纵向)。

I have tried putting 'android:screenOrientation='landscape' in my activity in my Manifest file. 我尝试在清单文件中的活动中添加“ android:screenOrientation ='landscape'。 But that does not fix it. 但这并不能解决问题。

Basically, what I want is when I rotate the phone by 90 % (the width is > height), I want the phone layout looks the same as what i see on tablet (which is landscape by default). 基本上,我想要的是将手机旋转90%(宽度>高度)时,我希望手机的布局与平板电脑上的外观相同(默认为横向)。

How can I do that? 我怎样才能做到这一点? android:screenOrientation='landscape' does not work. android:screenOrientation ='landscape'不起作用。

Basically, I want some thing the game 'AngryBird', it always runs in landscape mode regardless it is phone or tablet and whether the phone is rotated. 基本上,我想要一些游戏“ AngryBird”,它始终以横向模式运行,无论是手机还是平板电脑,以及手机是否旋转。

我自己还没有完成此操作,而是尝试将main.xml布局放置在res / layout-land中,而不是将其放置在res / layout-land中,这样它将以横向模式和res / layout-port中显示此布局main.xml的肖像替代品?

Create folder \\res\\layout-land\\ and place there your XML file with landscape layout. 创建文件夹\\res\\layout-land\\然后将您的XML文件放置在横向布局中。 Phone choose between portrait and landscape layouts automatically. 手机会自动在纵向和横向布局之间进行选择。

在调用setContentView之前,将此行添加到onCreate方法中:

setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE );

I think you need to use 2 flags, not just one. 我认为您需要使用2个标志,而不仅仅是一个。

First is 首先是

android:screenOrientation='landscape' 

Second is 第二个是

android:configChanges="orientation"

First will tell android to run activity in landscape mode, where as second will tell android that do not change the orientation even when user rotates the phone. 首先将告诉android以横向模式运行活动,其次将告诉android即使用户旋转手机也不改变方向。 Basically with 2nd flag you are overriding orientation config changes. 基本上使用2nd标志,您将覆盖方向配置更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM