Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Screen Orientation programmatically using a Button

I think this is implementable since screen rotation behaviour can go up to the application level.

like image 700
Sam Avatar asked Aug 16 '13 07:08

Sam


People also ask

How do I add a rotation button?

Swipe down twice from the top of your screen and then tap the gear-shaped settings icon in the lower-right corner of the Quick Settings panel. Tap “Display.” Scroll down until you see the line that says “Auto-rotate screen.” Tap it.

How do I lock orientation in android programmatically?

setRequestedOrientation(ActivityInfo. SCREEN_ORIENTATION_LANDSCAPE); Called on an activity, will lock it to landscape.


1 Answers

Yes it is implementable!

ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 

ActivityInfo.SCREEN_ORIENTATION_PORTRAIT

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 

ActivityInfo

http://developer.android.com/reference/android/content/pm/ActivityInfo.html

Refer the link:

Button buttonSetPortrait = (Button)findViewById(R.id.setPortrait); Button buttonSetLandscape = (Button)findViewById(R.id.setLandscape);  buttonSetPortrait.setOnClickListener(new Button.OnClickListener(){     @Override    public void onClick(View arg0) {         setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);    }  });  buttonSetLandscape.setOnClickListener(new Button.OnClickListener(){     @Override    public void onClick(View arg0) {         setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);    }  }); 

http://android-er.blogspot.in/2011/08/set-screen-orientation-programmatically.html

like image 149
Hariharan Avatar answered Oct 15 '22 05:10

Hariharan