如何设置应用程序片段只肖像模式? [英] How to set application fragments to portrait mode only?

查看:147
本文介绍了如何设置应用程序片段只肖像模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android应用程序有一个主要活动和3个片断这是标签。我想在任何时候都保持在纵向模式下的应用程序,但我似乎无法得到这个工作。这是我已经试过了,按照另一个堆栈溢出职位,但我不知道我做错了什么....它需要使用,如果碎片是不同的?

I have an Android app which has a main activity and 3 Fragments which are tabs. I would like the application to remain in portrait mode at all times but I can't seem to get this working. This is what I have tried, as per another stack overflow post, but I'm not sure what I'm doing wrong....does it need to be different if using fragments?

    <activity
        android:name="com.tutorial.test.activities.act1"
        android:label="@string/app_name" 
        android:screenOrientation="portrait"
        android:configChanges="orientation|keyboardHidden" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

感谢您!!

编辑:ViewPager是在FragmentActivity对此我设置screenOrientation如上

The ViewPager is on the FragmentActivity for which I am setting the screenOrientation as above.

推荐答案

试试这个..

您可以使用编程试试。

rootView 在Java中加入这一行 getActivity()setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

After rootView in your java add this line getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

对于

View rootView = inflater.inflate(R.layout.activityxml, container, false);       
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

和也是在您的清单中改变它的android:configChanges =方向| keyboardHidden的android:configChanges =keyboardHidden

And also in your manifest change it android:configChanges="orientation|keyboardHidden" as android:configChanges="keyboardHidden"

<activity
        android:name="com.tutorial.test.activities.act1"
        android:label="@string/app_name" 
        android:screenOrientation="portrait"
        android:configChanges="keyboardHidden" >

这篇关于如何设置应用程序片段只肖像模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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