问题描述
我有一个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" >
这篇关于如何设置应用程序片段只肖像模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!