Screen Orientation of Android - android

Which is more appropriate to use in Screen Orientation.
Declaring <activity android:screenOrientation="sensor" />
or
the long process of creating a new folder layout-land & a new layout? and why? I'm using the first
one now and seems it has the same function as the latter. Thanks!

I think the two are different. When we use android:screenOrientation we're telling android what orientation we want to be displayed in. Having two layout's, one for portrait and another for landscape helps us in cases where we want to layout our views such that it takes advantage of the increased width. If you don't think if need this then just use a single layout. Android will use the same for both orientations.
If you want to prevent android from displaying your view in a particular orientation, etc you can use the former.

sensor just returns the orientaton of the device. It does not optimize the layout like using layout-land would.
From http://developer.android.com/guide/topics/manifest/activity-element.html#screen
The orientation is determined by the device orientation sensor. The
orientation of the display depends on how the user is holding the
device; it changes when the user rotates the device. Some devices,
though, will not rotate to all four possible orientations, by default.
To allow all four orientations, use "fullSensor".

Related

Android app displays correctly after device rotation but I haven't coded for it. How comes?

I've been searching docmentation and forums, and from all I've read so far, I conclude that in order to support portrait and landscapce modes, I need to code two identically named layout XML files, one in res/layout, the other in res/layout-land. Each layout places the widgets corresponding to the mode.
But what if there is no corresponding layout in res/layout-land (or if the later doesn't even exist)?
From a simple app containing a single text view in a ConstriantLayout, I see that the layout correctly adapts to the device orientation when run on my physical phone.
However, when run on a virtual device (Pixel 4 XL API 28, if that matters), the view is not changed when I click on the Rotate left or Rotate right buttons.
But, after clicking on the rotate button, a rotate icon appears at the bottom right of the virtual device. Clicking on that rotates the view.
Basically, my questions are:
Why is the layout correctly rotated on my physical device despite the fact that no landscape layout is present?
Why does the virtual device not rotate the layout when clicking on the rotate buttons, but offers me a rotation by displaying a temporary rotate icon?
A pointer to some documentaiton where all this is described in detail would be nice. It sure must be documented; I just haven't been able to find it.
Devices have a setting to enable or disable auto-rotation - on newer devices, when this is off, that rotate button appears which allows the user to choose to rotate (i.e., manually rotate).
As per the providing alternative resources, the most specific matching resource is used. So if you had a layout in layout-land, it will take precedence over that same resource in layout. (but wouldn't apply at all if you where in portrait mode as -land would disqualify that alternative resource).
That means that alternative resources are entirely optional - you'd only use them if your layout needs to be very different from one configuration to another. ConstraintLayout, for instance, uses relative positioning (i.e., position a view relative to the parent or to another view), which is often quite flexible to different orientations, screen sizes, etc. thus removing any need to need an entirely different landscape layout for a simple layout.

Changing the orientation of buttons, letting the activity to remain in only one orientation

Assuming that the current android's activity is set to:
android:screenOrientation="sensorPortrait"
Is there any way to change the orientation only for buttons? So that the other childs stay in the same orientation, as stated in android manifest.
What I'm asking is related with a streching camera preview. As long as the android:screenOrientation is set to some value like landscape or portrait, then the switching to different orientations doesn't really affect the camera preview, the ratio and size is perfect. But when it comes to just remove this screenOrientation part in order to make the buttons rotate with the phone, so that they follow changing orientation....the landscape preview gets stretched like x2.5 time, making the preview look bad.
For all whom might look for the answer, concerning stated question, there are smart way to achieve this, just follow these topic above
Rotate an ImageButton on orientation change
How to rotate views on orientation change without recreating layout?

Is there any way to change the orientation of the layout shown in the second screen when using cwac-presentation library?

I have an app that uses the cwac-presentation library. When starting the service and displaying the layout on the second display, I want it to be landscape oriented but keep the layout on my device on portrait, but I cannot find a way to these different orientations. If I request an orientation change, it happens on both screens (as expected). Has anyone found a solution to this issue?

Android - How to stop screen adaptation to rotation

I am a newbie to the android world, and as of today I completed my first application.
I test my work on a physical device, and quite recently it has came to my attention that whenever I turn/rotate my device, my application tries to adapt itself to the new resolution 800x400.
Since I have designed the whole app for 400x800 resolution, this change messes up the original design, as well as sending a new call to "onCreate" method of the last activity it was on, before turning/rotating the device.
I would like to learn whether it is possible or not, or which class I should use to stop the adaption to resolution.
This line (in AndroidManifest.xml) will lock the activity in portrait mode:
<activity android:name="MyActivity"
android:screenOrientation="portrait" />
There are things that you can do to make your layouts work well in different orientations and resolutions, such as using dips instead of pixels to measure your views.
When you have time, consider making layout files for landscape mode. Create a "layout-land" directory within your res directory and drop he landscape layout files there, using the exact same file names for their portrait counterparts.

android device rotation

how can i get the rotation of the device in the four main orientations? and is there a corresponding event that i can capture?
also, is it possible to disable this rotation for my app?
thanks!
Explains how to get the size and orientation of the screen.
http://indyvision.net/2010/02/android-screen-size-orientation/
However, the device already changes its own behavior depending on the device orientation. For instance you can specify screen layouts dependent on the orientation, one for vertical and one for horizontal.
To prevent the Activity from rotating with the device, you can add android:screenOrientation="portrait" or "landscape" to AndroidManifest.xml for each Activity declared in your app.

Categories

Resources