如何解决方向问题?

发布于 2024-12-21 03:37:30 字数 829 浏览 2 评论 0原文

当我将屏幕从纵向模式更改为横向模式时,然后自动从我的应用程序中出来。(也与横向到纵向相同)任何人都可以告诉我解决方案。

这是我的方向代码,

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

弃爱 2024-12-28 03:37:30

如果您在 portraitlandscape 模式下具有相同的布局,那么最好通过

android:configChanges="orientation|keyboardHidden"

在 Activity 标记中添加属性 来停止旋转更改时重新创建 Activity清单文件。

If you have same layout in portrait as well as in the landscape mode then its better to stop the re-creation of Activity on rotation change by adding

android:configChanges="orientation|keyboardHidden"

attribute in your activity tag in the Manifest file.

羁客 2024-12-28 03:37:30

您错误地处理了方向变化。您应该阅读处理运行时更改指南。也请考虑这一点

You incorrectly handle the orientation change. You should read Handling Runtime Changes guide. Consider this as well.

亚希 2024-12-28 03:37:30

您有两个选择:要么以单一模式阻止应用程序:纵向或横向。
第二个选项是创建两个布局: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.

生寂 2024-12-28 03:37:30
int o = getBaseContext().getResources().getConfiguration().orientation;
    if(o==1)//Portrait
    {
             Log.i("Portrait","=====");

    }
    else if(o==2)//Landscape
    {
             Log.i("Landscape","=====");
    }               
int o = getBaseContext().getResources().getConfiguration().orientation;
    if(o==1)//Portrait
    {
             Log.i("Portrait","=====");

    }
    else if(o==2)//Landscape
    {
             Log.i("Landscape","=====");
    }               
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文