如何旋转应用内容



我已经对OrientationEventListener和检测屏幕方向有了很好的理解。但是,我如何旋转或调整实际内容(按钮,图像,选项卡,任何对象)?现在,当用户旋转手机时,内容不会移动或旋转,而是向用户显示侧面。

注意:我正在使用Droid 2进行测试,我注意到如果我滑出键盘,屏幕确实旋转,这在我看来有点奇怪。

任何帮助都非常感谢!

编辑:这是我的代码:

OrientationEventListener ole = new OrientationEventListener(this) {
        @Override
        public void onOrientationChanged(int arg0) {
            TabHost ll = (TabHost) findViewById(android.R.id.tabhost);
            try {
            ll.forceLayout();
            } catch (NullPointerException e) {
                System.exit(0);
                e.printStackTrace();
            }
        }
    };
    ole.enable();

不幸的是,当程序到达ll.forceLayout()时,它会抛出NullPointerException并导致系统关闭。

已解决:我必须编辑清单,使android:screenOrientation="sensor"。谢谢你的帮助!

,但我不知道如何告诉android切换到第二个视图当屏幕旋转

你不需要告诉它。如果你只是在你的项目中创建了一个layout-land文件夹,当设备进入横向模式时,系统将知道从该文件夹中拉出布局文件。

尝试在onOrientationChanged.

中为根视图调用forceLayout ()

把android:screenOrientation="sensor"从你的manifest中去掉。

最新更新