How to only allow specific layout states be used during gameplay - android

I'm using eclipse and I'm trying to figure out how to only allow a Portrait state be used during game play. I can't seem to find any options in eclipse to block the Landscape state.
I'd appreciate any assistance. I know it's probably a simple matter, but I can't seem to find it and I've not tried to do this before.
Thanks in advance.

In your AndroidManifest file you can achieve this. You will add the android:screenOrientation tag in your application declaration. Something like this
<application
android:icon="#drawable/logo"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:screenOrientation="portrait" > //HERE
<activity
android:name="com.test.SomeActivity"
android:label="#string/app_name" >
You can change that to landscape as well. This attribute can also be applied to individual activities instead of the whole application if you need that.

In the activity tags of your manifest file, add this:
android:screenOrientation="portrait"

Related

Android studio 3.6 give an redline for android:screenOrientation="portrait", need to change android:screenOrientation="fullSensor"?

When I update the android studio 3.6 its give me a red line below android:screenOrientation="portrait".
And its say's to change to android:screenOrientation="fullSensor"
Can anyone have any idea what is the reason behind it?
In Android studio 3.6.0 i guess they want the user to handle the orientation and encourage developer to use ViewModel stuff. Let me explain screenOrientation in detail
android:screenOrientation="portrait"
will give you error you have to either specify
android:screenOrientation="fullSensor" or android:screenOrientation="unspecified"
fullSensor Means either you have ON the "Rotate off" or not it will change the orientation based on you move the phone
unspecified Means if you have ON the Rotate off then it will stay only in that orientation and if not then it will change the orientation based on you move the phone.
To build on Deep Sheth's answer, this is a warning not an error.
As it suggests you set the fullSensor or unspecified in your activity so that the user can use the application in any orientation and provide a great experience in Chrome OS devices.
You can make that warning go away by adding the following to your activity declaration in the manifest: tools:ignore="LockedOrientationActivity"
I have used bellow ..
Add manifest file bellow lines ..
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="LockedOrientationActivity">
manifest file will look like..
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.yourpackage"
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="LockedOrientationActivity">
.....
<activity
android:name=".MainActivity"
android:theme="#style/AppTheme.NoActionBar"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden"/>
</manifest>

Stop App Screen Rotate to the Side

My app stops from working for some reason when the phone is rotated to the side and so the app does too. How can I avoid this, making it so it appears only vertically? Thanks a lot
add this to your activities in android manifest :)
android:screenOrientation = "portrait">
Here is a full example:
<activity
android:name=".Activity.MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait">
</activity>
In your app's manifest file, set activity to be vertical... Its easy...

How to keep my views from being redrawn

I have a simple app. And I would prefer the views stay the way they are when the orientation change. How can I do that?
Thanks in advance!
Add android:configChanges="keyboardHidden|orientation" to the activity in the manifest file..
<activity
android:name="..." android:configChanges="keyboardHidden|orientation">
</activity>
And read Handling Runtime Changes
In addition to #Nunu's answer you may wish to override onConfigurationChanged(...) to make any essential changes to your views.
You can also lock activities to portrait or landscape in the manifest.
EDIT
To lock in portrait declare your activity in the manifest like this:
<activity
android:name="com.yourpackage.YourActivity"
android:screenOrientation="portrait" />
you should check the sample application of "Multiresolution" in your android-sdk-windows /samples directory

Android, landscape only orientation?

How can I make it so the screen orientation is always landscape?
Do I need to add something to the manifest.xml?
Add this android:screenOrientation="landscape" to your <activity> tag in the manifest for the specific activity that you want to be in landscape.
Edit:
To toggle the orientation from the Activity code, call setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) other parameters can be found in the Android docs for ActivityInfo.
Yes, in AndroidManifest.xml, declare your Activity like so: <activity ... android:screenOrientation="landscape" .../>
Just two steps needed:
Apply setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); after setContentView().
In the AndroidMainfest.xml, put this statement <activity android:name=".YOURCLASSNAME" android:screenOrientation="landscape" />
Hope it helps and happy coding :)
One thing I've not found through the answers is that there are two possible landscape orientations, and I wanted to let both be available!
So android:screenOrientation="landscape" will lock your app only to one of the 2 possibilities, but if you want your app to be limited to both landscape orientations (for them whom is not clear, having device on portrait, one is rotating left and the other one rotating right) this is what is needed:
android:screenOrientation="sensorLandscape"
When you are in android studio 3 or above
you need to add following lines AndroidManifest.xml file
<activity
android:name=".MainActivity"
android:configChanges="orientation"
android:screenOrientation= "sensorLandscape"
tools:ignore="LockedOrientationActivity">
One thing this is sensor Landscape, means it will work on both landscape sides
But if you only want to work the regular landscape side then, replace sensorLandscape to landscape
You can try with
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

Forcing 'portrait' orientation not working - any tips?

Hey all - I have tried to only display my app in portrait view orientation to no avail.
I have the code: android:screenOrientation="portrait" in every button, ImageView, TextView, etc... in my xml files but when I tilt the phone to the side, it still goes into landscape view.
I do call the camera in my app, but I don't think that is the issue - any thoughts?
the layout is the wrong place. you have to place it in the activity like this:
<activity android:screenOrientation="portrait" ...>
Force an Android activity to always use landscape mode
is google that hard to understand? google "android force portrait" and the first four links shows the answer... (sorry.. just had to let it out :) )
You have to put the android:screenOrientation="portrait" in the AndroidManifest.xml.
In AndroidManifest.xml you have to do something like this:
<activity android:name=".Your_Activity_Name"
android:configChanges="keyboardHidden|orientation"
android:screenOrientation="portrait"/>

Categories

Resources