How to fix layout orientation to portrait and do not allow changing from portrait to landscape during run time?
In your AndroidMainfest.xml file find the tags of the activities you wish to lock to a given rotation, and add this attribute:
android:screenOrientation="portrait"
Use setRequestedOrientation() as shown:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
in your activity parameters in Manifest File
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.statepermit" android:versionCode="1" android:versionName="1.0">
<application android:icon="#drawable/stateheader" android:label="#string/app_name">
<activity android:name=".statepermit" android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="7" />
</manifest>
android:screenOrientation="portrait"
If you want to freeze orientation at runtime, then you you can implement this:
Android: Temporarily disable orientation changes in an Activity
I use a similar approach and it works perfectly.
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
before
setContentView(R.layout.main);
If you want to fix the orientation of one Activity in your project, you have to open the Manifest.xml and put in the section of parameters of the desired Activity (before the closure of the first tag < activity…> ):
android:screenOrientation="portrait" if you want VERTICAL fixed orientation
android:screenOrientation="landscape" if you want HORIZONTAL fixed orientation
In your AndroidMainfest.xml just write this in your activity you declare,
If you want in layout vertical than use
android:screenOrientation="portrait"
If you want in layout landscape than use
android:screenOrientation="landscape"
Related
Hello everyone I am new in Sherlock Actionbar I am having a very strange problem in my sample application. The problem is that when I rotate to landscape from the portrait its behavior is normal but when I rotate back to portrait mode the layout does not change back to portrait mode.
Below are the screen shot of the problem I am facing.
OriginalScreen
Did rotation to Landscape
Again rotated back to original orientation i.e. Portrait Mode
As you can see that on the third picture the problem I am facing.
I am using the latest version of ActionbarSherlock library.
Edited
My manifest File
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.actionbar_sherlockexample"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.actionbar_sherlockexample.MainActivity"
android:theme="#style/Theme.Sherlock"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Thanks
This is an issue with emulator . If you will run it on real device , it will work fine .
I have the main Activity which has 4 images on the canvas with the screen Orientation as "portrait". When I traverse to the child Activity which has the screen Orientation as "landscape".
Issue : When I come back from the child Activity to the main Activity the 4 images are relocated to different position. I need to resolve this so that the Activity is fine even for the change in screen orientation.
Thanks in Advance.
Layout
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black">
<activity
android:name=".DragDrop"
android:label="#string/title_activity_main"
android:screenOrientation="landscape"
android:configChanges="orientation|screenSize|keyboardHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".QuizHard"
android:label="#string/title_activity_main"
android:screenOrientation="landscape"
android:configChanges="orientation|screenSize|keyboardHidden" >
<intent-filter>
<action android:name="android.intent.action.QUIZHARD" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
you can set the orientation to portrait of main activity and landscape of child activity in android manifest file.
<activity android:name="Main"
android:screenOrientation="portrait"/>
similarly set orientation to landscape for child activity.
You can add statements to your AndroidManifest.xml file to tell it to handle certain screen changes, such as orientation changes. Normally, when the orientation changes, a new layout is loaded and the screen is recreated, by adding this statement to the manifest file, it won't recreate the view. Change the activity declaration of your activities and add this statement.
<activity
android:name=".MainActivity"
android:configChanges="orientation"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
The android:configChanges="orientation" will prevent Android from recreating the activity, thus preventing it from reloading the view and changing the image positions. You can also add android:screenOrientation="portrait" right after the configChanges statement if you want Android to lock the orientation to portrait, or landscape, if you want.Hope this helps! Would love to hear back from you with the results.
You can add orientation to activity in manifest like this
<activity android:name="Main" android:screenOrientation="portrait"/>
or you can set layout orientation in java file like this
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
I have designed an activity that its orientation is landscape. Also I have designed another that its orientation is portrait. When I run in my phone, there are some problems comes to when the landscape activity back to the portrait activity.
Some of the layout disappear, such as below
original:
after
can anyone help me to solve this problem?Thank you so much!
<activity android:name="TestingActivity" android:screenOrientation="portrait" android:configChanges="orientation" > </activity>
<activity android:name="Main">
<intent-filter>
<action android:name="android.intent.action.MAIN"></action>
<category android:name="android.intent.category.LAUNCHER"></category>
</intent-filter>
</activity>
<activity android:name=".TestingActivity2" android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen" android:screenOrientation="landscape" />
Your problem is in layout-portrait xml file. You can fix it by redesigning it. Please post your code.
I am finding that in my Android application, the name of the application is displaying on the top of every screen, consuming a line of valuable screen real estate.
I am using LinearLayouts
How can I get this not to display?
You can set it in the Activity/Application tags in the manifest XML:
android:theme="#android:style/Theme.NoTitleBar"
See more here (Styles and Themes).
Or write in onCreate yours Activity before setContentView():
requestWindowFeature(Window.FEATURE_NO_TITLE);
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen">
<activity
android:name=".A"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
you can add this line android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen" to the manifest and make your application fullscreen and without title bar
and if you want to remove only the title bar and don't want to make the application full screen then you can use Theme.NoTitleBar
Change your activities' theme like that
<activity android:name=".Activity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
android:theme="#style/AppTheme"
Above change in Manifest file didn't work for me.
requestWindowFeature(Window.FEATURE_NO_TITLE)
For this to work in your project you have to make one more change. Make your acivity extends Activity instead of AppCompactActivity which comes by default.
Thank You.
I have meet a problem, there is a tabhost in my app.which have 4 tabs,each tab have more than one activiy.I just want to fix some of activities in portrait mode while other's can change orientation mode,any suggestions?
<activity android:name=".MyTabHost"
android:windowSoftInputMode="adjustPan|stateVisible"
android:configChanges="keyboardHidden|orientation"
></activity>
<!-- android:screenOrientation="portrait" -->
<activity android:name=".Products_Images"
android:configChanges="keyboardHidden|orientation"
></activity>
<activity android:name=".Products_Upload"
android:screenOrientation="portrait"></activity>
<activity android:name=".Products_Description"
android:screenOrientation="portrait"></activity>
in products_images.java,i just want to show larger image while orientation changed,however in products_upload.java and products_description.java,i just want to fix orientation in portrait mode, all three class just in one tab.but it doesnt work!!
use this in activity tag in manifest file:
android:screenOrientation="portrait"