在android活动中是否有任何方法可以禁用逆向景观和反向纵向定位。我用的是下面的code.but逆向景观就来了。
rotation = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay().getRotation();
System.out.println("Rotation Value : " +rotation);
if(rotation==0){
System.out.println("portrait");
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);}
if(rotation==1){
System.out.println("landscape");
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);}
if(rotation==2 )
{
System.out.println("reverse portrait");
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
}
if(rotation==3)
{
System.out.println("reverse landscape");
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
}
发布于 2015-04-01 07:54:05
将android:configChanges="keyboardHidden|orientation“添加到AndroidManifest.xml中。这将告诉系统您将自己处理的配置更改,在本例中,不做任何操作。
<activity
android:name="MainActivity"
android:screenOrientation="portrait" //This line only if you want to lock your screen Orientation
android:configChanges="keyboardHidden|orientation|screenSize">
有关更多细节,请查看http://developer.android.com/reference/android/R.attr.html#configChanges。
然后重写onConfigurationChanged:http://developer.android.com/guide/topics/resources/runtime-changes.html
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks the orientation of the screen
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
}
}
https://stackoverflow.com/questions/29385404
复制相似问题