我想以纵向模式运行我的应用程序,我知道这不是最佳做法,但有理由这样做.虽然我已经禁用了旋转,但它仍然可以在某些视图上旋转,而在其他视图上则不会.
<activity android:name="<name>.app.MainActivity" android:label="@string/app_name" android:configChanges="keyboardHidden|keyboard|locale|orientation" android:screenOrientation="portrait">
解决方法
你可以做下面这样的事情
在java中的rootView之后添加这一行
getActivity().setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // programmatically
对于Ex:
View rootView = inflater.inflate(R.layout.activityxml,container,false); getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); And also in your manifest change it android:configChanges="orientation|keyboardHidden" as android:configChanges="keyboardHidden" <activity android:name="com.test.activity" android:label="@string/app_name" android:screenOrientation="portrait" android:configChanges="keyboardHidden" >