Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 degree upside down when user rotate the device 180 degree upside down so it will adjust accordingly and displays to the user properly.At present if I am rotating device 180 degree upside down, My application doesn't adjust accordingly as per the rotation so it will display in reverse (from bottom to top) for example: suppose my activity is having 2 text fields on the top and 2 buttons on the bottom so if you rotate device 180 degree upside down, Activity is not adjusting accordingly, so user can see buttons on the top and text fields are on bottom which is wrong it should adjust/rotate as per the device rotation and must display text fields on the top and buttons on bottom.

Please provide your valuable solutions to resolve this problem.

Regards, Piks

like image 785
piks Avatar asked Apr 03 '12 05:04

piks


2 Answers

specify:

android:screenOrientation="sensorLandscape"

in your AndroidManifest.xml. This will transform application between landscape and reverseLandscape.

like image 86
Ankit Aggarwal Avatar answered Oct 06 '22 06:10

Ankit Aggarwal


In your AndroidManifest.xml file, you need to configure the <activity> 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 <activity> with android:configChanges="orientation".

like image 32
Sean Owen Avatar answered Oct 06 '22 07:10

Sean Owen