I decided to develop my own camera activity since I need to force the user to take a 1:1 ratio picture; just like Instagram. I created my activity based on this activity from an open-source project:
https://github.com/pocorall/scaloid-apidemos/blob/master/src/main/java/com/example/android/apis/graphics/CameraPreview.java
Now I'm trying to handle the screen rotation to avoid the layout from being rotated. In other words, I want to keep the layout from rotating and rotate only the buttons and the status bar depending on the device rotation.
I already declared my activity to listen for config changes in the manifest file.
<activity
android:name=".activity.CameraActivity"
android:configChanges="orientation|screenSize"
android:theme="#style/Theme.Eyes.NoActionBar"
android:windowSoftInputMode="adjustNothing|stateHidden">
</activity>
Stop rotation of layout
Add android:screenOrientation="portrait" into manifest
Detect rotation for individual buttons
Call Display.getRotation() to check how much the screen has roated and adjust buttons accordingly
Related
I have an activity with "portrait" orientation in AndroidManifest.xml.
When I start it from lock screen in landscape orientation, it appear with landscape for 1 second, and then change to portrait. The delay happens even if it's an blank activity (no view, no task).
Tell me how to avoid this delay. Remove transition effect, rotation effect? I know it could be device performance, but still want to fix this.
If you always wants to run your app in landscape mode than use this code in Manifest file for all activity
<activity
android:name=".yourAcitvity"
android:launchMode="singleTask"
android:screenOrientation="landscape"
android:configChanges="orientation|screenSize"
/>
That't the default behavior of Android, you can verify this issue using system apps. For ex: open the Android's default messenger, and turn it to landscape and lock the phone, now unlock it and you can see the messenger has re aligned to portrait, that's because the home screen is set to portrait by default. In order to show the home screen the system aligns the device to portrait again.
There is an android program
I have a bottom navigation bar inside my app that i don't want to change its orientation because of quality reduce
I want to rotate a fragment inside an activity when change orientation of the phone without activity rotation. how can i do this?
Thanks.
Open your Manifest.XML
Find your activity.
Add tag inside
<activity
android:configChanges="orientation"/>
I am using Listview
I'm playing video (on VideoView) on portrait mode (not on full screen) and when I change to
landscape mode the video stop.
When I change it to landscape that video will appear on full screen and will keep playing.
Any Suggestion?
You can add this in your manifest for that activity, and ensure the activity does not redraw the views.
<activity
android:name=".YourActivityName"
android:configChanges="orientation|screenSize">
</activity>
Please note that if you have handled the orientation changes for this activity separately, then adding this would skip that.
I'm using an android search dialog in my app, and it works fine in Portrait orientation. But as soon as you flip to landscape orientation the searchpage xml appears to be covered by a large white dialog box. If you do a search, the box is still there, and you hit the back button on the device or emulator, the large white box slides away and there are your search results. It seems like somehere in the code a layout width is set to fill_parent or something. I've looked around for a solution and someone suggested adding android:imeOptions="flagNoExtractUi" to seachable.xml in the xml folder, but that doesn't seem to have any effect.
I've discovered that it's the onSearchRequested(); method that is throwing up that white box that fills the screen. And it also may have something to do with the fact that the software keyboard isn't called when in landscape, vertical orientation.
You could create your own Dialog in the form of an Activity. You do that like this:
<activity
android:theme="#android:style/Theme.Dialog"
android:configChanges="keyboardHidden|orientation|screenSize"
android:name="ExampleActivity" >
</activity>
This Activity can of course be arranged any way you like via the XML. This way, you can gracefully handle the change from portrait to landscape.
Note: You only need the "screenSize" attribute if you are using ICS (14+).
I observed one problem in status bar that while we open it from the home screen and change the device to landscape mode, the orientation of the status bar is not changed to landscape,
but if we open any applications like messaging in which their orientation is changed according to device orientation and then open the status bar, it will also change the orientation.
That means keeping an application who orientation is constant in background and then opening the status bar will have this problem that orientation of status bar also becomes constant.
Please give me some suggestions so that I can rectify this problem. If I could know that who is parsing the xml file and if android:configChanges="keyboardHidden|orientation" is present in the manifest file who is deciding not to send Intent.ACTION_CONFIGURATION_CHANGED
you should prepaire to create landscape layout also.
for landscape mode-> layout-land
for portrait mode-> layout
android:configChanges="keyboardHidden|orientation" , this tag used when we dont want to change state in our activity when orientation is changed
if android:configChanges="keyboardHidden|orientation" is present in the manifest file then our activity will handle itself one or more configuration changes that we specify and need not to handle by android system.That means when we use android:configChanges="keyboardHidden|orientation" we tell android system that our activity itself controll this configuration change.