Android screen orientation: lock only parts of the layout

I am creating a camera application that uses a camera preview. To use the full screen for preview, I blocked the action with

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 

Now I have the following problem: whenever I render a form or should show a dialog, it is always displayed in landscape mode, even when the user uses his device in portrait mode. I tried to rotate the edittext views using the cast animation, and they are rotated correctly, but still I can no longer focus them, and the keyboard always appears in the landscape :(

Do you know ANY way to find a way here?

IMPORTANT: determining orientation is not a problem here. The question arises: how do I rotate forms / views / viewing groups and the keyboard so that they are still usable.

I know this should be possible somehow: the samsung camera app (which comes with the S3 galaxy) is able to rotate views without turning the preview, so it should be possible! cm:

http://www.letsgomobile.org/images/reviews/0186/galaxy-s3-camera.jpg

http://cdn2.mos.techradar.futurecdn.net//art/mobile_phones/Samsung/GalaxyS3/Galaxy%20Fire/Samsung_Galaxy_S3_25-580-100.JPG

+6
source share
6 answers

The Samsung Camera app uses an orientation change listener with an orientation sensor. If the user blocks the rotation of the device from the settings, the rotation still occurs.

You will need to create your own custom widgets, so you cannot use build in Dialog, you need to show CustomDialog ....

The main idea is to use OrientationEventListener and SensorManager. When rotating the device, you must update your interface and rotate the views with a new orientation. Here's a guide to using OrientationEventListener How to use OrientationEventListener In most camera apps, activity is still blocked in LANDSCAPE. All camera apps do this trick to simplify the processing of resizing SurfaceViews using rotation.

+2
source

Setting this property

 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 

You lock your screen only for LANDSCAPE, after that, even if the user holds the device in portrait mode, it will not be turned into portrait mode. You can do one thing according to my understanding of your problem.

 android:configChanges="orientation" 

In the manifest file, add this property above to your activity. And in the Activity class, override the ConfigurationChange method, where you can handle orientation changes according to your needs, instead of blocking the Activity to Landscape.

If I understand your problem correctly, this may help you.

+2
source

You need to redefine the behavior of this operation by turning the device, you need to add the orientation to your mafist, and then add a listener for this event and manually rotate your views.

And if you use this method, the whole dialog box, etc. (system views) will display correctly.

Check this out: http://developer.android.com/reference/android/app/Activity.html#ConfigurationChanges

And this: How to deal with a change in screen orientation with an active dialog and background thread? (second answer, I think)

0
source

it’s better to try to use another action as a dialogue and set its properties (orientation and theme) in the manifest and use it.

0
source

In your manifest file, give the following android:configChanges="keyboardHidden|orientation" camera view activity properties android:configChanges="keyboardHidden|orientation" for more details this

 <activity android:name=".Your_Activity_Name" android:configChanges="keyboardHidden|orientation" android:label="@string/app_name" > <intent-filter> <!-- Your filter attributes if any. --> </intent-filter> </activity> 

And in your activity class, redefine onConfigurationChanged and make the orientation screen (as necessary, landscape or portrait) (as necessary) as follows:

 @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); // Checks the orientation of the screen if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show(); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); //Your code to do the other things in landscape mode... } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){ Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show(); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); //Your code to do the other things in portrait mode... } } 

I hope this helps you get rid of your problem.

0
source

afaik: rotation is achieved by capturing orientation events and inflating the screen with a new layout in accordance with this orientation.

  • landscape bloat
  • rotation occurs
  • inflate the parts of the screen that you want to change, for example, we inflate the view of the button holder with a new location for the portrait buttons instead of landscape.

You should have your own layout cut into pieces that you add together at runtime.

Another way to achieve this is to use surface views to preview the camera and use a different layout to hold the surface and add a framelayout on top of it

0
source

All Articles