how to set landscape orientation in particular activity?
To lock your Activity during runtime, you can use
// lock orientation to landscape
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
All you need now is to determine the current orientation, and pass it to keep it locked that way.
First, add these imports:
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
Then you can add this to your Activitys onCreate():
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// lock the current device orientation
int currentOrientation = this.getResources().getConfiguration().orientation;
if (currentOrientation == Configuration.ORIENTATION_PORTRAIT){
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
else{
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
// ... rest of your code
}
See ActivityInfo documentation for the other orientation configurations.
Android Studio - landscape only but still rotate
You should add the sensorLandscape
screenOrientation
tag to your activity in the android manifest file and you should be good to go.
android:screenOrientation="sensorLandscape"
Make sure to add this to all the activities that you want to have in landscape mode.
how to force an Android app into landscape only or portrait only?
<activity android:name="Intro"
android:screenOrientation="portrait"
android:label="@string/app_name">
<intent-filter>
<action android:name="com.gmaninc.package.INTRO" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
one of the following in each activity in the manifest
android:screenOrientation="portrait"
android:screenOrientation="landscape"
Android Rotation Landscape Only
Use android:screenOrientation="sensorLandscape"
instead.
Landscape orientation, but can be either normal or reverse landscape based on the device sensor. Added in API level 9.
See Dev Guide
Note that if you use android:configChanges="orientation"
to avoid screen rotation in the activity tag, the screen will not rotate at all. If you want it to rotate only in landscape, use the option described above and remove the orientation flag. Check what is the behaviour you want before using this option or not.
Android force orientation one way only
I believe you can find what you need here:
activity | Android Developer #android:screenOrientation
There are more options than landscape and portrait, I believe the ones helpful to you would be "reverseLandscape" and "sensorLandscape". Since the volume button differs from tablet to tablet, you may want to use "sensorLandscape" and ask the user turn their tablet to such orientation, just a suggestion.
Edit: Just saw you said you are building for one device, I guess "reverseLandscape" will do just fine.
Android: Force landscape orientation but allow rotation
You just need to set the android:screenOrientation
attribute in your AndroidManifest.xml to sensorLandscape
Android App Landscape Only
Use android:screenOrientation="sensorLandscape"
but it will work only if you are building your project on Android 2.3 or above.
Related Topics
Google Map Android API V2 Can't Display Map in Play Store Application
Android Sharedpreferences , How to Save a Simple Int Variable
How to Set Searchview Textsize
Changing Locale: Force Activity to Reload Resources
Java.Io.Ioexception: Unexpected End of Stream on Connection in Android
Onkeylistener Not Working with Soft Keyboard (Android)
Creating a Product Sdk: How to Add a Native Lib (.So) and a Jar with the Sdk I am Creating
Detecting Gps On/Off Switch in Android Phones
How to Get Bluetooth Connected Devices Using Bluetoothheadset API
Proguard Warnings "Can't Write Resource [Meta-Inf/Manifest.Mf] (Duplicate Zip Entry)"
Can't Access "Findviewbyid" in Asynctask
How to Pass Arraylist<Hashmap<String, String>>From One Activity to Another
Android:How to Change Playback Rate of Music Using Opensl Es