Android - Prevent Apps from Rotation Landspace or Portrait
If you want your app to have either of one fixed position: Landscape or Portrait, you can do it by setting the orientation in AndroidManifest.xml using android:screenOrientation attribute.
Example :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.code2care.tools.example"
android:installLocation="auto"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature android:name="android.hardware.camera.flash" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:installLocation="auto"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" >
<activity
android:screenOrientation="portrait"
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".App"
android:label="@string/app_name" >
</activity>
</application>
</manifest>
Note: If you have two or more activities then you need to set the orientation for each of them separately.
Example :
<!--Activity 1 --!>
<activity
android:screenOrientation="portrait"
android:name=".Screen1"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--Activity 2 --!>
<activity
android:screenOrientation="landscape"
android:name=".Screen2"
android:label="@string/app_name" >
</activity>
More Posts related to Android,
- Share or Send SMS via Android Intent
- java.lang.NoClassDefFoundError android.support.v4.content.LocalBroadcastManager
- Fixed Length Android Edittext
- Error:The SDK Build Tools revision (XX.X.X) is too low for project. Minimum required is XX.X.X
- Android Emulator] ##KBD: Full queue, lose event Error Logs
- Pass data between two Android Activities and access it using Intent
- AlertDialog with no buttons (just text message)
- Android Eclipse This version of the rendering library is more recent than your version of ADT plug-in. Please update ADT plug-in
- Can't Run SDK Manager find_java.bat issue
- Android Studio Native typeface cannot be made error
More Posts:
- How to make Android EditText not editable - Android
- Indent XML Formatting In Notepad++ - NotepadPlusPlus
- Send Extra Data with Ajax Get or Post Request - JavaScript
- How to un-hide tab bar in notepad++ - NotepadPlusPlus
- Disable Back Button in Android Programmatically - Android
- 97 Useful Notepad++ Keyboard Shortcuts - NotepadPlusPlus
- How to verify if java is installed on the computer and get version detail - Java
- Eclipse like Auto Import Shortcut in Intelij IDE Android Studio - Android-Studio
- [Solution] Installing Whatsapp There's insufficient space on the device - WhatsApp
- Unhandled exception type InterruptedException : Java Threads - Java
- Delete blank lines in a file using Notepad++ - NotepadPlusPlus
- fill_parent vs match_parent vs wrap_content - Android
- XmlRpcException ConnectException connection refused error - Java
- How to Setup maven on Mac OS X - Mac-OS-X
- Android ListView turns Black or Flickers while Scrolling - Android