如何让手机的应用程序运行在纵向和横向上的平板电脑 [英] How to make application run portrait in phone and landscape on tablets

查看:132
本文介绍了如何让手机的应用程序运行在纵向和横向上的平板电脑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在寻找了解这些,这样我可以给更多优秀的布局和我的应用程序的UI进出口。我想我的应用程序必须在手机的情况下,我可以在的Andr​​oidManifest.xml

Hi I am looking to learn about these so that I can give more good layouts and UI exp of my application. I want my app must run only in portrait mode in case of phone that I can set in the AndroidManifest.xml like

    <activity
        android:name=".SplashActivity"
        android:label="@string/title_activity_splash"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

不过,这将让所有的手机和平板电脑。如果我做这样的话当然我的布局不会好看月7日和10英寸的屏幕。

But This will keep for all phones and tablet. If I do this way then of course my layout won't look good on 7 and 10 inch screens.

如何设置使得在手机肖像模式和横向模式7和10英寸的屏幕我的应用程序运行。

How to set such that my app run in portrait mode in mobile phones and landscape mode on 7 and 10 inch screens.

先谢谢了。

推荐答案

创建值名为bools.xml一个新的文件,如下文件夹:

<?xml version="1.0" encoding="utf-8"?>
    <resources>
    <item type="bool" name="isLargeLayout">false</item>
</resources>

创建另一个文件价值观大文件夹命名bools.xml如下:

create another file in values-large folder named bools.xml as below:

<?xml version="1.0" encoding="utf-8"?>
    <resources>
    <item type="bool" name="isLargeLayout">true</item>
</resources>

在打电话给的setContentView 获得这个资源之前,你的活动现在并根据其价值决定端口或陆地方向:

Now in your activity before calling to setContentView get this resource and based on its value decide port or land orientation:

boolean isLargeLayout = getResources().getBoolean(R.bool.isLargeLayout);
if(isLargeLayout) {
    // Tablet Mode
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else {
    // Handset Mode
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}

这篇关于如何让手机的应用程序运行在纵向和横向上的平板电脑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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