简体   繁体   English

Android屏幕方向横向错误?

[英]Android Screen orientation landscape error?

I'm new to android and making an app in which there is layout design for both portrait and landscape mode. 我是android的新手,正在制作一个同时具有纵向和横向模式布局设计的应用程序。 The app is running fine in both screen orientation except for one activity. 除了一项活动外,该应用在两个屏幕方向上均可正常运行。 The activity is working fine in portrait mode when i go from one activity to another, but crashes in landscape mode. 当我从一项活动转到另一项活动时,该活动在纵向模式下工作正常,但在横向模式下崩溃。 I tried to solve this in different ways through Google search but didn't succeed. 我试图通过Google搜索以不同的方式解决此问题,但没有成功。 Please someone help me. 请有人帮我。 Thanks 谢谢

希望在AndroidManifest.xml的活动代码中使用此android:configChanges="orientation" ,希望这会有所帮助

Make two different resource folders in res folder like below: 在res文件夹中制作两个不同的资源文件夹,如下所示:

1) layout --> put your main.xml 1)布局->将您的main.xml

2) layout-land --> put your same main.xml in here too. 2)layout-land->也将您的main.xml放在这里。

Note: in both res folders the name of layouts must be same. 注意:在两个res文件夹中,布局的名称必须相同。

Edit: well android handles orientation change automatically after above mentioned 编辑:好的android会自动处理方向更改后上述

procedure.. but if you want to handle it manually then here is the code to handle.. 程序..但是如果您想手动处理它,那么这里是要处理的代码..

public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);

if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) 
{
  Do something in Portrait
} 
else if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
{
  Do something in Landscape
}
}

Add this below line in your manifest to the activity you want to handle orientation: 将清单中的以下行添加到要处理方向的活动中:

android:configChanges="orientation|screenSize|keyboardHidden" android:configChanges =“ orientation | screenSize | keyboardHidden”

Use this in Manifest. 在清单中使用它。

<activity android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden" android:name="VncCanvasActivity">

This line specifies the screenOrientation as landscape, but author goes further in overriding any screen orientation changes with configChanges="orientation|keyboardHidden" 此行将screenOrientation指定为横向,但作者在使用configChanges =“ orientation | keyboardHidden”覆盖所有屏幕方向更改方面走得更远

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

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