Android activity not rotating on phones (but does on tablets) - android

I have an activity that does not rotate on some devices, but does rotate on others.
Specifically it rotates on tablets tested so far, but not on phones. My other activities with the same manifest parameters do rotate as expected.
This view has a viewpager as well as admob ads. Is there a known bug/feature with these layout elements that can override rotation parameters? I don't have anything saying the orientation should stick to landscape or portrait in the manifest or in the code.
If there isn't anything known, I can post code later.

The answer is that this theme
android:theme="#android:style/Theme.Translucent.NoTitleBar"
doesn't allow rotation on certain screen sizes

In manisfest insert the activity parameter android:configChanges="orientation" and not insert the screenOrientation parameter.

Related

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?

Android: Orientation Issue

I have an activity that shows a video. I want this view to show only on landscape, so I have my AndroidManifest.xml as follow:
<activity
android:name="uk.co.tangent90.ciscoDelegateBag.android.activities.ViewVideoActivity"
android:label="#string/registerViewTitle"
android:screenOrientation="landscape"
android:configChanges="keyboardHidden|orientation" >
</activity>
It is working almost fine:
If I am in portrait, the view rotates as expected.
If I am already in landscape, can happen 2 things:
The view remain as it is. OK.
The view rotate 180 degrees. NOT OK
It is depending on if I have the front camera in the right or in the left. So it is like android only recognizes ONE landscape orientation.
Has anybody have this problem before? Any easy way to fix it?
Thanks.
Use
android:screenOrientation="sensorLandscape"
Refer <activity> documentation for values screenOrientation can take.
Can you try the following?
android:configChanges="keyboardHidden|orientation|screenSize"
Use screenSize if you are using minimum sdk version above 13.
If your application targets API level 13 or higher (as declared by the
minSdkVersion and targetSdkVersion attributes), then you should also
declare the "screenSize" configuration, because it also changes when a
device switches between portrait and landscape orientations.
Android recognizes only one rotation as landscape, the other, 180° degrees rotated "landscape" orientation is called "reverseLandscape", you can only use one of them, in fact, most of the apps that show videos only work in one orientation.
EDIT: try as Rajesh said "sensorLandscape"

lock screen rotation but detect it anyway

I m building an app which an a main layout in portrait format
I locking orientation with
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
However, I need to detect screen orientation changes anyway because I want to load another Activity if the screen is rotated.
How to do that ?
I tryed onConfigurationChanged but it s never called.
Some things to look at if onConfigurationChanged isn't firing:
When you declare the manifest, make sure you have defined at least orientation and screenSize for the activity configChanges. Like this:
<activity android:name="com.test.act" android:configChanges="orientation|screenSize">
Make sure the device doesn't have rotation blocked. For example if you are using a Nexus 7:
http://www.howtogeek.com/120056/how-to-enable-landscape-orientation-on-the-nexus-7s-home-screen/

Screen Orientation of 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".

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