Android support fragment animation problems - android

I have created an app that uses fragment animations for loading and unloading fragments.
I have saved the animation xml files in res/anim folder and passing it in setCustomAnimation method.
The animations worl flawlessly on my Kitkat phone but on my another FroYo phone, no animation takes place and the things just appear normally.
The weird fact is that the view animations are working on both devices.
I have tried setting the hardwareaccelerated attribute to true but that dint solve it either
Can you please help?

There's a bug on Android pre-ICS where durations set on an AnimationSet in XML are not respected. To fix this, apply the animation duration to all child animations in the AnimationSet instead.

Related

How to animate the color of the whole screen (all visible views/layouts) when changing to NightMode in Android?

I know there is ObjectAnimator / ValueAnimator for Property Animation in Android, and also one can set the system-wide night mode with UiModeManager.setNightMode(int):
https://developer.android.com/reference/android/app/UiModeManager#setNightMode(int)
How could we make a color animation when switching from DayMode to NightMode? (Currently I'm using the latest Huawei phone and find no animation there, not sure if other Android phone has this feature?)
try using MotionLayout with keyTrigger
check the documentation: https://developer.android.com/reference/android/support/constraint/motion/MotionLayout#keytrigger
Hi I think the best you can do is create a light and dark theme for your app in the style.xml file.
here is a github link of someone who achieved this with a simple code example. there is even a video of how it will look.
it seems like the animation is some android default fade_in/fade_out anim but personally i think it looks nice enough. let me know if this works for you

How to create flip animation in android?

I have a tablelayout with multiple viewFlipper in each square. What I want is whichever viewflipper i touch, the view should flip. Everything is working fine but what I need is this kind of animation.
The animator files given there cannot be used in viewFlipper.setInAnimation(this, android.R.anim.fade_in);. We need to use anim for it not animator.
Android do give some built in animations but all of them are fade, slide etc but not flip. I think flipping is one of the most used animations, why isn't android providing one in default or am I missing something ?
You can try github library - Flip 3D View.
Finally I was able to solve this. Although there is a library but you need not used the whole library just for flipping views. check out this tutorial. Basically you create an animator xml as shown in the android guide in question. Then you can use it to animate any object not only views. Just use it like this
Animator flipAnimator = AnimatorInflater.loadAnimator(this,R.animator.card_flip_left_in);
flipAnimator.setTarget(cardView);
flipAnimator.start();

android lollipop ViewGroup child hierarchy changes?

I have an app that has a minSdk of 15 and I'm working out all the bugs that came with the lollipop upgrade. Our software is very complex and it dynamically creates views using custom ViewGroups and then an array of elements that are explicitly sized and placed inside the group. I'm running into an issue where for example I'll have a ViewGroup and the first child object is a Button...this button is sized to fill the view (not clickable). The second child is a FrameLayout containing a single view. This single view is a video object. In all prior versions of Android this works just fine. The FrameLayout is layered over the button (that is acting as a background) and the video is inside the framelayout. You can interact with the video without any issues.
Something changed in lollipop - suddenly, even though the button is showing up as the 0 index element, it is laying OVER the rest of the children...so I cannot get to the video underneath. If I remove that button element, the video renders and plays just fine...I have no issues interacting with it.
I ran the app in UI Automator Viewer just to make sure I was really setting up the UI as I expected (keep in mind the entire view is dynamically rendered at runtime using image/video assets and xml config files).
I'm not able to share code since this is proprietary software, but I am working on a little test project to see if I can manually recreate the issue with static objects. Once I get that up and running I'll be sure to update this ticket. For now, here is a screenshot of the hierarchy:
https://goo.gl/photos/a8on9CJDnN66XYnV6
Notice the highlighted object, this is the custom ViewGroup, the children below it are what I am describing above.
Does anyone know of a change in Lollipop that would effect the ordering of things? I found earlier that if you have a disabled object but don't have a disabled state drawable assigned to that object it would become invisible, previous versions just used one of the other state drawables..okay that makes sense and it was very easy to fix, but this object is not invisible...so it must be something different.
Any direction would be greatly appreciated.
~A
UPDATE -- FIXED
With the help of #alanv and #BladeCoder I figured out this functionality was due to the new elevation feature of Material design. I was able to fix my particular issue by first checking what version of android the device was using, and if lollipop, I just add this new property to the button:
android:stateListAnimator="#null"
This prevents my explicit child hierarchy from being overridden by the OS.
Lollipop introduced elevation as a way to position the elements on the Z axis and cast shadows between them depending on their difference of elevation.
Enabled buttons have a default elevation of 2dp (and it increases when you press them). So, your button has a higher elevation than the FrameLayout (0dp by default) so it will be drawn on top of it.
Disabled buttons have an elevation of 0dp. That's why disabling the button solved your issue.
Using buttons as backgrounds looks like a bad idea (why not setting a custom Drawable background on your FrameLayout instead?) but if you really need that, you can disable the button like you did and, just to be sure, enforce its elevation to 0dp. Another workaround is to increase the elevation of the FrameLayout but then it may cast a big shadow under Lollipop if it has a background, and maybe that's not what you want.
Okay, UPDATE! I figured out how to fix the issue, although I'm still not sure (even after pouring over the diffs between several classes in grepcode) what changed in lollipop that is causing a change in how this works.
If the button is enabled...and you are placing it using something equivalent to AbsoluteLayout (We have our own ViewGroup we created called Explicit layout, but it does pretty much the same thing as AbsoluteLayout), it will always be on top of anything else in the stack that isn't also a button of some sort (at least that's what I'm finding...I didn't test through every possible widget).
Setting the button that is acting purely as a background image to enabled=false solves this issue. I know, it doesn't make sense that we use Buttons as background images, but our code uses it for dynamic element creation so there are many possible states and uses for each element.
Anyway, not sure if anyone else would even run into this issue, but just in case you do...here it is.
Thanks!

Webview glitches in shared element transition on lollipop

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.

Use custom Animation (MyAnimation extends Animation) to transition between two Fragments

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.

Categories

Resources