如何在Android的编程控制横向和纵向? [英] How to control landscape and portrait programmatically in android?

查看:201
本文介绍了如何在Android的编程控制横向和纵向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发的应用程序使用的Andr​​oid SDK 4.0,我安装的.apk文件在我的三星标签。当我运行该应用程序能正常工作。如果我更改选项卡纵向到横向或反向屏幕上也发生了变化。

I developed on application using android sdk 4.0 and I install that .apk file in my samsung tab. When I run that application it is working properly. If I change the tab portrait to landscape or in reverse the screen also changed.

但我的要求是不考虑改变模式,无论是纵向到横向,以景观为纵向的,我的应用程序应该仅在纵向模式下运行。

But my requirement is irrespective of changing the mode either portrait to landscape to Landscape to portrait, my application should run in portrait mode only.

推荐答案

添加机器人:screenOrientation =肖像在您的manifest.xml文件每个活动

add android:screenOrientation="portrait" for each activity in your manifest.xml file.

您可以做到这一点编程也为所有的活动作出 AbstractActivity 你所有的活动延伸: - 。

You can do this programmatically too, for all your activities making an AbstractActivity that all your activities extends.:-

public abstract class AbstractActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
}

这篇关于如何在Android的编程控制横向和纵向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆