如何解决方向问题?
当我将屏幕从纵向模式更改为横向模式时,然后自动从我的应用程序中出来。(也与横向到纵向相同)任何人都可以告诉我解决方案。
这是我的方向代码,
if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
Toast.makeText(MyAlphabetsActivity.this, "ORIENTATION_PORTRAIT",
Toast.LENGTH_SHORT).show();
setContentView(R.layout.portrait_main);
System.out.println("int-----1--");
} else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
setContentView(R.layout.landscape_main);
Toast.makeText(MyAlphabetsActivity.this, "ORIENTATION_LANDSCAPE",
Toast.LENGTH_SHORT).show();
System.out.println("int-----2--");
}
当将纵向更改为横向时控制输入else if()并显示Toast按摩也......
When i changed screen from portrait mode to land scape mode then automatically came out from my application.(same as landscape to portrait also)can any one tell me the solution for this..
this is my code for orientation,
if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
Toast.makeText(MyAlphabetsActivity.this, "ORIENTATION_PORTRAIT",
Toast.LENGTH_SHORT).show();
setContentView(R.layout.portrait_main);
System.out.println("int-----1--");
} else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
setContentView(R.layout.landscape_main);
Toast.makeText(MyAlphabetsActivity.this, "ORIENTATION_LANDSCAPE",
Toast.LENGTH_SHORT).show();
System.out.println("int-----2--");
}
when change portrait to landscape control entered into else if() and display Toast massage also.......
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您在
portrait
和landscape
模式下具有相同的布局,那么最好通过在 Activity 标记中添加属性 来停止旋转更改时重新创建 Activity清单文件。
If you have same layout in
portrait
as well as in thelandscape
mode then its better to stop the re-creation of Activity on rotation change by addingattribute in your activity tag in the Manifest file.
您错误地处理了方向变化。您应该阅读处理运行时更改指南。也请考虑这一点。
You incorrectly handle the orientation change. You should read Handling Runtime Changes guide. Consider this as well.
您有两个选择:要么以单一模式阻止应用程序:纵向或横向。
第二个选项是创建两个布局:layout-land 和layout-portrait
有两种不同的布局是不正确的。它就是行不通。
您必须拥有 res 文件夹中的文件夹。一个文件夹布局区域,其中包含 main.xml
还有一个文件夹布局肖像,其中有一个也称为 main.xml 的文件,用于处理肖像模式。
You have two options: either you block the application in a single mode: portrait or landscape.
Second option is to create two layouts: layout-land and layout-portrait
It is not correct to have two different layouts. It just not work.
You must have to folders in res folder. One folder layout-land in which you have your main.xml
And a folder layout-portrait in which you have a file called also main.xml with handling the portrait mode.