2016-07-22 171 views
1

正如标题不工作反向画像说。当我尝试使用反向风景时,它工作正常。这并没有什么意义。我做错什么了吗?提前致谢。在android系统

回答

1

试试这个代码。

public class MainActivity extends AppCompatActivity { 

    @Override protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
    } 

    @Override 
    protected void onResume() { 
     super.onResume(); 
     Settings.System.putInt(getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0);// turn off rotation according to accelerometer 
     Settings.System.putInt(getContentResolver(), Settings.System.USER_ROTATION, Surface.ROTATION_180);//reverse portrait 
    } 

    @Override 
    protected void onPause() { 
     super.onPause(); 
     Settings.System.putInt(getContentResolver(), Settings.System.USER_ROTATION, Surface.ROTATION_0);//portrait 
     Settings.System.putInt(getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 1);//turn on rotation according to accelerometer 
    } 
} 

不要忘记添加权限的AndroidManifest.xml

<uses-permission android:name="android.permission.WRITE_SETTINGS"/> 
+0

真棒!有用。 – philip