Just a general question here. I've read that it is not possible to lock orientation to portrait or landscape in a relative layout. I developed the app already so I don't want to change my layout and have to delete everything in my layout and start over, but if I have to I will. So is there anyway to workaround this like turn auto rotate off on the device the app is installed? Please don't go research and waste your time to find a workaround because it isn't a necessity. So once again thanks for reading and any help is greatly appreciated. Bye!
You can define orinetation in AndroidManifest.xml
<activity android:name=".NameOfTheActivity"
android:screenOrientation="portrait"/>
Related
I know this :
android:screenOrientation="landscape"
But depending on which orientation you open the app, the way changes (even if it's landscape, there're 2 ways).
How can I force an app to open one way?
For clarity sake, I really want the volume button at the bottom of the tablet only.
Though I know it changes depending on which constructor I'm building my app for a single device, so I wonder if that is possible.
Try with this in onCreate() method of Activity
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
You can just lock the landscape orientation this way :
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
Or if you want the reversed landscape orientation :
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
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.
Don't forget to put in the manifest file where the activity is defined!!!
Best regards
You can also add to manifest file this option:
android:screenOrientation="portrait"
or
android:screenOrientation="landscape"
I've searched stackoverflow for this and didn't get any solution to what I am looking for.
In my manifest file I am writing the following line for each activity
android:screenOrientation="portrait" android:configChanges="orientation|keyboardHidden"
But still, all the activities rotate to landscape on tilting the phone.
How can I solve this issue ?
"Once upon a time I was a confident developer in C/C++,iOS,Java,Javascript,C# but thank you android! now I can't even look eye to eye in mirror!"
May be this will help
In your manifest file after your main activity write below line
android:screenOrientation="portrait"
Or in your coding after setContentView() add this line..
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
I'm currently creating a side-scroller style game for my final year project for my degree.
I'm just wondering how you make the menu designed for when the phone is in horizontal orientation display, even when the phone is held in it's vertical orientation?
i.e. I want the user to know that the game has to be played with the phone in it's horizontal orientation and want the menu's to only display in the horizontal orientation.
Many thanks in advance.
Add the following attribute to your activity in your AndroidManifest.xml:
android:screenOrientation="landscape"
Well, I didn't get your question right,
but if you are defining your menu via xml
create a new folder in your res folder named
for layout changes:
layout_land
for horizontal specific menu:
xml-land
for horizontal specific drawables:
drawable-land
and define your menu,layout and drawable changes there.
Further you can tell android framework that you want to handle rotation changes:
by adding to your manifest(AndroidManifest.xml) activity child
android:configChanges="keyboardHidden|orientation"
android:screenOrientation="landscape"
Comment exactly what you want.
Cheers!
Just complementing on other's answers
There are some different types of landscape and I think the best one is:
android:screenOrientation="userLandscape"
because it lets the user switch to landscape or reverse landscape using the device's sensor, or the user can block the swithing if he decides to.
I found that removing some basic controls of the user is quite annoying and should only be used if really necessary.
If you want to checkout other possible orientations just go here
I have application which works only in landscape orientation . I set that in xml layout. When I'm starting application it works ok . But when the application is started and next if I lock the phone and then unlock, the application first 1-2 seconds is in portrait mode and then in landscape. Is it possible to skip theese 2 seconds?
Try defining it explicitly in your manifest. Add android:screenorientation="portrait" to each <activity> element.
Not to be a downer, I really hope you solve this. Just wanted to throw out there that I have noticed this sort of behavior(typically for me the apps are supposed to stay in portrait but they show landscape for about 2 seconds) on multiple applications on my Sprint HTC Hero, including the default home application and many of the default included apps (contacts, etc). I am beginning to suspect it's an android problem. Again, feel free to disagree with me, but I just wanted to say that I have noticed this on a lot of apps & you're not alone here :/ However, there are some apps that I have not noticed it on, so either a) I am just getting lucky or b) there is a correct solution
Execute this in your onCreate(), just before setcontentview:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
I use this method in my apps and I never notice the orientation changing. It's locked solid into the requested orientation.
To be provocative, actually, what he needs to put in each activity element in his manifest is:
android:screenOrientation="landscape"
and not "portrait"
:P
I hope this help; put these on every activity-element in your Android Manifest-file.
android:configChanges="orientation"
android:screenOrientation="landscape"
Of course it is landscape; my brain was not the quickest this time.
This question already has answers here:
Force "portrait" orientation mode
(12 answers)
Closed 2 years ago.
I'm pretty close to finished with my first game for Android, and I've come across a problem that's so simple I'm sure I'll feel stupid for not knowing how to solve it, but how can I force the app to stay in a Horizontal layout? Right now, if you turn the phone (emulator) it flips the graphics and squeezes them. I want the game to start horizontally and stay that way regardless of how the user turns the phone.
Thank you.
Open the AndroidManifest.xml and add the following android:screenOrientation="landscape"
e.g.
<activity android:name=".ActivtyName"
android:screenOrientation="landscape"
>
To do this at the Activity level, in case you want to change it dynamically or allow the user to select the orientation, use setRequestedOrientation in your Activity's onCreate method.
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
etc...
In the AndroidManifest file, try add android:screenOrientation="landscape" to the activity's attribute.
e.g.
<activity android:name=".myMainActivity"
android:screenOrientation="landscape">
Or, you could use a R.styleable file and set the Orientation settings there. More info
I think you should be able to set
android:screenOrientation="landscape"
on your Activity in the manifest. It doesn't look like there's an Application wide setting, so you'll probably need to do it for each Activity separately.
Here is an easier way might help someone having same problem and dont want to deal with xml. You can go to Application Nodes select your activity and select screen orientation. See the image attached for clarity.