Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run the application in Landscape mode only?

I want to run a Hello World sample application only in landscape mode on my Device.

If the device changed to portrait, I would then like to raise one toaster. For example "please change to landscape mode to run your application".

How should I do this?

like image 852
Praveenkumar Avatar asked Sep 23 '11 07:09

Praveenkumar


People also ask

How do I run an app in landscape mode?

You can use the configChanges -attribute for the Activity you want to catch the screen-orientation change for. After that, the onConfigurationChanged() -method in your Activity will be called when the orientation changes.

What is the meaning of landscape mode?

What Does Landscape Mean? Landscape is a horizontal orientation mode used to display wide-screen content, such as a Web page, image, document or text. Landscape mode accommodates content that would otherwise be lost when viewed to the left or right. Portrait mode is landscape's counterpart.

Why do some apps not work in landscape mode?

Ensure that you have enabled Auto-rotate for your tablet. To do this, swipe down on the tablet to display the status bar and touch Auto Rotate.


2 Answers

You can go for both programmatically as follows:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

or also in manifest file you can give here as

<activity android:name=".YourActivity"  android:screenOrientation="landscape" android:configChanges="keyboardHidden|orientation"/>
like image 123
Android Killer Avatar answered Oct 21 '22 17:10

Android Killer


add this to your activity tag in your manifest file:

android:screenOrientation="landscape"

It will fix your orientation to landscape mode and you need not to show any toast to user.

like image 25
Vineet Shukla Avatar answered Oct 21 '22 17:10

Vineet Shukla