how to rotate a fragment inside an activity without activity rotation? - android

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"/>

Related

Different WindowSoftInputMode for activity and fragment

I want to achieve the functionality shown in the image. Let me explain the scenario in details.
I have a main activity and several fragments. what I want is when the keyboard is open the activity will remain same (will not resize) but the fragment will change its height and will be shown above the keyboard.
I have tried to do this using android:windowSoftInputMode="adjustResize" and android:windowSoftInputMode="adjustPan" for activity and getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); in onCreateView of the fragment. But its not working properly. I am getting this.
is there any way to solve this?

On Orientation change cannot update the fragment view in android

I have a MainActivity.java which has 2 fragments:
1) Fragment1.java -> Has a RecyclerView of items.
2) Fragment2.java -> Displays the details of the item when it is clicked.
In Portrait orientation only Fragment1.java or if item clicked then Fragment2.java is visible.
In Landscape mode both the fragments are visible side by side.
This works fine in both Portrait and Landscape orientations if I start the app in that orientation.
However if I change the orientation in between when the app is still running, then I get the error IllegalStateException : Cannot perform this action after onSaveInstanceState whenever another list item is clicked. The action on which it throws the error is transaction.commit().
Any idea how I can fix this?
I would suggest seeing if you have set the Orientation mode in the activity tag in the manifest and if you did remove it.Android handles this automatically.
such as :
<activity
android:name=".MyActivity"
android:screenOrientation="portrait" />
Regarding the different looks of the fragments when the app is in Landscape or Portrait , this has to do with the Layout you choose in the xml file.
Relative , Linear etc. Please checkout the Android official documentation and use that meets your needs.

Android rotate only status bar and buttons

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

How to make a one fragment screen always in landscape mode and reamaining not.?

I have one activity which i am using as host for calling all my fragments.I am using setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) for setting screen in landscape mode.But problem is that it is making every fragment in landscape mode because their is only one parent activity for all of them.I can not use android:screenOrientation="landscape" because this will also work the same.
I want one of my fragment to be displayed always in landscape mode and remaining fragment as according to device orientation.Is their is another ways for doing it?
If you wanna show one specific Fragment in landscape you can call
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
in the onCreate() of your Fragment.
In this Fragments onPause() f.e. you can call
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
which is the default value and enables screen rotation changes.

How to preserve orientation during a popup?

I am using menu in an activity to display a popup window.
The problem is that when the orientation is changed, the popup window disappears and the activity screen is shown again.
(It happens because when the orientation is changed the Activity is started again)
i want that the activity doesnt start again and after orientation change the popup window doesnt vannish.
please chenge activity in manifest file
put in activity below code
android:configChanges="orientation"
Please make the following changes to manifest where you defined your activity
add this lines:
android:screenOrientation="landscape" or
android:screenOrientation="portrait"

Categories

Resources