Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do we set the orientation of an activity in Android, based on the device?

I have a situation, wherein, if the Android device is a tablet, then I want the orientation to be enabled (portrait and landscape), whereas if the device is a phone, I want the orientation to be only in Portrait mode. Can you help me how to do this?

Thanks, Nithin

like image 695
nithinreddy Avatar asked Feb 13 '12 06:02

nithinreddy


People also ask

What is orientation in Android How is it done?

Screen Orientation, also known as screen rotation, is the attribute of activity element in android. When screen orientation change from one state to other, it is also known as configuration change. There are various possible screen orientation states for any android application, such as: ActivityInfo.

How can we detect the orientation of the screen in Android?

int orientation = display. getOrientation(); Check orientation as your way and use this to change orientation: setRequestedOrientation (ActivityInfo.


1 Answers

You have 2 methods :

a) Create different sets of layout and drawables for the phone and tablet separately and design them according to the orientation you need.

b) Check for the operating device during runtime and set the orientation. To check the device , give a check on the following parameters and set the orientation programatically,

  (1) Build.VERSION.SDK_INT
  (2) Configuration.SCREENLAYOUT_SIZE_MASK
like image 127
HjK Avatar answered Oct 27 '22 16:10

HjK