I'm trying to make it so the screen can't rotate when you turn it because it screws up some of the graphics. Is there a way to do this?
Just Add android:screenOrientation="portrait" to your <activity> tag in the manifest to disable orientation.
You can also try to stop the activity from recreating itself when rotating by adding this
android:configChanges="orientation|screenSize|keyboardHidden" to your <activity> tag.
Related
I have an activity that always rotates in the 2 view modes(portrait and auto-rotation) but want it to rotate only in auto-rotation mode.
I have set in my manifest
<activity
android:name=".Controlling"
android:screenOrientation="portrait">
</activity>
but when I am in portrait mode (when the activity should be fixed), it is still rotating.
I was looking to do it programmatically by using
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
but still does nothing
Do you know how to do it?
Try to change out android:screenOrientation="sensorPortrait" in AndroidManifest.xml
If you are doing it from fragment then you need to give an activity context.
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);
Try with this and let me know it works for you or not.
I have a adobe form which I need to incorporate in my mobile app which I created in application craft, But since the form is a little wide, opening it in Landscape solves my purpose. This is the reason I need the page to be fixed in Landscape while other pages will rotate according to the phone movement.
The only thing I have got is that there is a phone gap property but it sets the orientation of the complete app and not a page. So is there any way to do it?
In the manifest, set this for all your activities:
<activity android:name=".YourActivity"
android:configChanges="orientation"
android:screenOrientation="landscape"/>
Let me explain:
With android:configChanges="orientation" you tell Android that you will be responsible of the changes of orientation.
android:screenOrientation="landscape" you set the default orientation mode.
In my application, most of the activities has fixed layout - portrait.
So I've mentioned in manifest:
<activity
android:name="com.example.activity5"
android:screenOrientation="portrait" />
But in one or two activities I've to show landscape layout also, in such a way that by default the activity opens in portrait mode. But if user tilts the phone to left/right it changes to landscape. (also if user rotates the phone to upside down, activity should not go to portrait mode).
That is, basically, I want orientation change in 3-way. Default(Potrait) & Left-Right(Landscape).
So, what changes do I need to do in my code & xmls?
Should I choose "sensorPortrait" OR "sensorLandscape"
Should I use android:configChanges="orientation"
I tried few steps, but they are throwing null pointer exception.
I dont know what I'm missing.
P.S. Both orientation have different layouts.
Thank You
I think you want to do this:
1) Just remove android:screenOrientation="portrait", and
2) In your code, in onCreate(), add this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
--(UNRELATED) SIDE NOTE--
To force landscape use this:
<activity android:name="com.example.activity5"
android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden" />
Write to Main.class(OnCreate):
setContentView(R.layout.activity_main);
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Can a live wallpaper lock the screen in portrait mode? And if so, how?
I should mention that I have seen two supposed answers to this question on SO, one appeared inordinately complicated, I didn't understand it all and the answer was not accepted by the original poster. The second answer didn't work for me.
A third answer involving the use of:
android:screenOrientatin = "portrait" or "landscape"
has been suggested, but it is not clear exactly where this should go in the manifest.
EDIT: have tried putting android:screenOrientation="portrait" in many different places in the manifest, and none of them worked.
EDIT: another answer was to rotate your bitmaps and handle a rotation by just drawing everything sideways - but this looks very ugly because, as you rotate you phone, the OS instigates a rotation animation - which means that you get a horrid jumping effect as you turn the phone.
I'm beginning to suspect that the true answer is simply "no".
Did you try setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); ?
In your AndroidManifest.xml you should have something like:
<application
android:icon="#drawable/app_icon"
android:label="#string/nuboLogin"
android:name=".LoginApplication"
android:debuggable="true">
<activity
android:name=".WallPaperActivity"
android:label="#string/wallPaper"
android:windowSoftInputMode="adjustPan"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen" android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden">
</activity>
This should make sure that your Activity runs in portrait mode. If you prefer landscape, you can easily guess what you should modify
Android application restarts the activity when the orientation changes. You can either use
android:configChanges in your manifest. The activity is shut down and restarted by default, when a configuration change occurs at runtime, but declaring a configuration with this attribute will prevent the activity from being restarted. Instead, the activity remains running and its onConfigurationChanged() method is called.
use android:screenOrientatin = "portrait" or "landscape" it will force the app to run in the mode you specify. However it will not prevent the activity from being shut down and restarted.
I want to disable the view change on device rotation for the time being. Its giving foreclose error when i rotate the device and starts all over again.
I have used tab activity everywhere.
How should i proceed ?
In your manifest, you can define which activities you don't want to rotate automatically by setting i.e.
android:screenOrientation="portrait"
You can add this on your manifest:
<activity android:name=".YourActivity"
android:screenOrientation="portrait"
android:label="#string/activity_label"/>
Ger
What you need to set is set the configChanges attribute of the activity in your manifest. This will still allow the user to rotate the 'phone, but tells Android not to restart your activity when it does so.