I am trying to do a transition between two fragments using a 'flip animation.' I made my flip animation by writing a separate class called Flip3dAnimation that extends Animation. I use this elsewhere in my app and it works as intended. I would now like to use it to transition between to fragments. I am aware that the following method exists:
setCustomAnimations(arg0, arg1) on a FragmentTransaction object, however the two arguments to this method has to be xml resources. Since I wrote my own animation I do not have any animation declared in xml and I do not know of a way to get my own Flip3dAnimation type to appear as a valid xml tag in a res/anim/my_animation.xml file. Is this possible?
If above solution is not possible, then how would this be done?
EDIT: I am aware of this tutorial, however as far as I understand, the <objectAnimator> tag is a property animation, which uses API level 11 and is not included in the support library. My app has to run on devices with Android older than 3.0, so this is not really an option, unless there is some way around it, that I do not know of?
Thank you.
Related
I have searched everywhere for an answer to the problem below without success.
I understand that there are two ways of visually connecting fragments during navigation: namely animations and transitions.
I have understood and used animations to connect two fragments but now I want to use the set transitions, not animations.
Here is the problem: I have two fragments, when the current fragment is replaced I want the second one to slide in - I suspect that using a built-in transition is simpler than an animation.
I get stuck at this point in the android developer's guide - only a code snippets are shown - what would the full xml resource file look like ?
All insights welcome
Solved. Just required a calm and close re-study of the Android Developer's guide on the 'Transitions Framework' and also The classes Fragment, Transition, TransitionManager, Fade, Slide.
My initial panic was caused by Android Studio opening a new xml file from the transition directory with an auto-template that began with the root tag <transitionManager> but files in the res/transition directory can begin with roots <transitionManager>,<transitionSet>, <transition> or simply the name of one of the built-in transitions such as <slide> with the parameters of the slide as attributes.
I can use FragmentTransaction#setCustomAnimation(int, int) method to define the animations when changing Fragments as described in this answer. However, this approach is limited to animations defined in XML files.
Is there a way to use programmatically defined animations when switching between Fragments?
Looks like there is no such option.
If I'd need to guess, I'd say that the reason is save&restore flow (aka. process death). It's easy to persist IDs of XML resources in Bundle when the app dies and retrieve them later, but it's much more difficult to re-create custom animation objects after the app is re-launched.
We can create animations using both android.animation package and android.transition package but I would like to know what is the main difference between these packages since even custom transitions also use animator's from android animation package.
From the documentation of android.animation:
These classes provide functionality for the property animation system,
which allows you to animate object properties of any type.
From the documentation of android.transition:
The classes in this package enable "scenes & transitions" functionality for view hiearchies.
From there a conclusion could be made that android.animation mostly handles individual View animation (a FAB moving left upon click, etc) while android.transition cares mostly about view hierarchy/layout transition animation (Material Design shared elements, etc).
do read about fundamental difference at http://developer.android.com/about/versions/android-4.4.html in 'Animation & Graphics' section. Basically, you can transition between different states of UI by defining Scene objects.
I don't have any code to support as i haven't used this till now, but above link should get you started.
I've just started to rebuild my app for Android 5.0, using the appcompat support library. I've just finished implementing a transition featuring shared elements. It seems to work well, untill I add a webview.
I've made a video to demonstrate the glitch.
https://www.youtube.com/watch?v=MuuGZc0Vwow
As you can see, all's fine when I open the activity. When I close it, the glitch occurs. As you can see all elements fade out like they should, except for the webview. Which just hangs there until the animation is over, kinda ruining the entire smoothness of the animation.
How do I fix this? If it could be related to the way I've set things up I'd be happy to share some code.
Thanks in advance.
The reason why this glitch occurs is because WebView extends AbsoluteLayout. By default ViewGroups that are not "transition group"s and that have no background drawable will not be animated by the activity's window content transition. In order to fix the glitch with the WebView, you will need to call webView.setTransitionGroup(true) (or set the attribute in XML using android:transitionGroup="true"). This should cause the WebView to fade away as part of the activity transition instead of simply sitting there until being abruptly removed at the end of the transition.
As for the "Unable to create layer for WebView" error you are receiving, I imagine that is because the transition framework automatically creates a hardware layer for the WebView during the transition and for some reason the framework is crashing when it is trying to create the layer. This sounds like a totally separate issue related to Android's internal graphic pipeline though... I'm not sure I can give you a good answer about why the crash occurs without more information.
This issue is also discussed in the bottom of this blog post.
I have facing exactly this kind of random crash problem in webview in Marshmallow version. I have add attribute android:transitionGroup="true". but crash is happening, after that i have added android:hardwareAccelerated="false" in manifest where that activity is declared. After that random crash has solved in Marshmallow version and lower version too.
I have an app and I'd like to use the Android CRT power-off animation built into Android 4.1 for my onPause activity transition animation. However, I have not been able to find out where this animation xml resides inside the Android source code. My guess would be that it's somewhere inside some sources as the animation seems fairly complex. It's not just a simple scale/translate thing.
This is how it looks like : http://www.youtube.com/watch?v=_zFwpb_LDHQ
You should check this animation mElectronBeamOnAnimator out, it's can be found in:
/frameworks/base/services/java/com/android/server/power/DisplayPowerController.java
And do not forget to set mElectronBeamFadesConfig to false, which will use mode ElectronBeam.MODE_WARM_UP, which is CRT effect.
As Bibek said, it uses openGL to draw this animation rather than just an xml file.
Hope this will help.
As far as I know, you can't. It's not a part of the SDK. You would probably have to create your own. I am guessing, it's not an XML, rather it would be some native code or at-least OpenGL.