Rameez Hussain
Rameez Hussain

Reputation: 6764

Android screen orientation detection without layout change

I want to detect layout change in my activity while keeping the widgets where they are. Is there any way to do this. I tried setOrientation(LinearLayout.HORIZONTAL) and it doesn't seem to work. Any ideas?

Upvotes: 1

Views: 651

Answers (2)

Bertrand Hieronymus
Bertrand Hieronymus

Reputation: 52

Try to add android:configChanges="orientation" in your manifest file in the activity and you may be able to get the orientation in the onResume method of your activity by using

if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE){
//WHAT TO DO IN LANDSCAPE
} else {
//WHAT TO DO IN PORTRAIT
}

Upvotes: 1

Vajk Hermecz
Vajk Hermecz

Reputation: 5722

As a lower level solution, you could use one of the Sensors, to detect the orientation/tilt of the device. If you don't want layout changes you can constraint your activity to portrait or landscape only in the manifest...

You can play with the app Elixir to see what values a specific sensor returns.

Upvotes: 0

Related Questions