screen orientation - reverse portrait - android

I have a very basic layout with a Frame and a TextView.
When I put my phone upside down (reverse portrait) the Text is not facing me, the screen does not rotate. Is it en intended behavior that by default the screen only rotate in 3 direction?
<TextView
android:text="Text"
android:textAlignment="center"
android:textSize="70dp"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
Manifest:
<activity
android:name=".Menu"
android:screenOrientation="user"/>
From what I could gather through researches it is part of the default settings of recent android OSs. Would I need to program anything complex to get this working? Or a small setting would do the job (like adding a layout)?
I target OS 5+ (API 21)

In your AndroidManifest.xml file, you need to configure the <activity> to use the orientation from the sensor. This should be the default, but you can force it to the sensor's orientations, for all 4 possible orientations, with android:screenOrientation="fullSensor"
<activity
android:name=".ui.MainActivity"
android:label="#string/app_name"
android:screenOrientation="fullSensor"
android:theme="#style/AppTheme.NoActionBar" />

Related

making steady layout position as from landscape or portrait

how to make the layout of the project app in android studio steady as the position i choose ,i mean how to make landscape or portrait in a steady position and don't change to vise versa as when enter the page the layout go to those positions by it's self and don't be able to be changed even if the device state changed?
< RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/inside"
android:layout_alignParentLeft="true"
android:layout_marginLeft="0dp"
android:layout_alignParentTop="true"
android:layout_marginTop="0dp">
In your manifest file you can force the layout of each Activity like this
<activity android:label="#string/app_name"
android:name=".MyActivityName"
android:screenOrientation="portrait" >
/* ... */
</activity>
or
<activity android:label="#string/app_name"
android:name=".MyActivityName"
android:screenOrientation="landscape" >
/* ... */
</activity>

locking the Iphone screen with phone Gap

I wanted to know if the phone gap allows you to lock the screen to one position and not change it's resolution when the user is turning his iphone/android device?
I'm Developing an app that is based on HTML/JS and don't want to build my UI Again when the user is turning his phone from side to side
Just To make Clear - I'm working inside the device browser with HTML/JS/Jquery
is it possible?
p.s my intention is presenting the app in portarit position
On manifest file, where you have the activities list, on activity node you should add:
<activity android:screenOrientation="portrait" ...../>
or
<activity android:screenOrientation="landscape" ...../>
depends on what you need.
You can set the orientation for your app in xcode for iPhone:
or in your android manifest file with:
<activity android:screenOrientation="portrait" .../>
or
<activity android:screenOrientation="landscape" .../>

How can we set in application run only vertically not horizontally? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
I want my android application to be only run in portrait mode?
I want to set the database for run only vertically not in horizontally so what changes in application ?
You can specify in your activity in manifest.xml how you want it to work
e.g
<activity
android:screenOrientation="landscape"> //for landscape ie horizontal
and
<activity
android:screenOrientation="portrait"> //for portrait ie vertical
If you want to make your application in force portrait mode you can to do by adding this in the manifest file :
<activity android:name=".activityName" android:screenOrientation="portrait" />
Your question is too vague.
To use your application only vertically (portrait) mode, then following changes you have to do in manifest file
<activity android:name=".YourActivity" android:screenOrientation="portrait">
This will allow your activity to run in vertical mode (portrait mode) only and its activity configuration will not be changed even if you change device orientation.
You do this in the AndroidManifest.xml file on the activity. Take a look at the Activity element documentation.
<activity android:name=".MyCustomActivity"
android:screenOrientation="portrait"
[...]
Programmatically you can do this in your activity as follows:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);

Android App Doesn't Stay in Portrait Mode

So I've set my manifest to keep the app in portrait mode, as this is how the game should be played. However, despite doing what I've seen others do, it still switches modes when you tilt the phone. Below is what I've done with the manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
...
android:screenOrientation="portrait">
...
<activity android:name=".GameActivity"
...
android:configChanges="keyboardHidden|orientation"
android:screenOrientation="nosensor">
I've always used
android:screenOrientation="portrait"
in each <activity> to good effect. Give it a shot.

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);

Categories

Resources