How to rotate my application 180 degree upside down upon rotating device 180 degree upside down?

后端 未结 2 1858
滥情空心
滥情空心 2020-12-31 10:56

I have developed one application and configured its orientation is Landscape so it will always display on landscape view on the device.

Now i want to rotate it 180

2条回答
  •  爱一瞬间的悲伤
    2020-12-31 11:33

    In your AndroidManifest.xml file, you need to configure the to use the orientation from the sensor. This should be the default, but you can force it to the sensor's orientations, for all 4 possible orientations, with android:screenOrientation="fullSensor". See http://developer.android.com/guide/topics/manifest/activity-element.html#screen

    EDIT: If you want to enable all but one orientation, you could disable that orientation by intercepting the orientation change event and quashing it in your Activity:

    public void onConfigurationChanged(Configuration config) {
      if (config.orientation != Activity.ORIENTATION_PORTRAIT) {
        setRequestedOrientation(config.orientation);
      {
    }
    

    (This is off the top of my head but think it works, or something nearly like it.)

    You need to tell Android to let the app handle orientation changes too in your with android:configChanges="orientation".

提交回复
热议问题