I am trying to implement a fragment transaction with insert / insert animation. I am developing a minimum of 14 sdk, so ObjectAnimator is the only option for me ( is there any other way? Animation translation is not available, as I understand it).
The code is very simple:
AnimationView.java - shell class
public class AnimationView extends LinearLayout { public AnimationView(Context context, AttributeSet attrs) { super(context, attrs); } public float getYFraction() { return getHeight(); } public void setYFraction(float yFraction) { final int height = this.getHeight(); setY((height > 0) ? (yFraction * height) : -9999); } }
Insert and remove xml
<?xml version="1.0" encoding="utf-8"?> <set> <objectAnimator xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:propertyName="yFraction" android:valueType="floatType" android:valueFrom="-1" android:valueTo="0" android:duration="600"/>
<?xml version="1.0" encoding="utf-8"?> <set> <objectAnimator xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:propertyName="yFraction" android:valueType="floatType" android:valueFrom="0" android:valueTo="1" android:duration="600"/>
The animation works fine , as you can see that I used the yFraction custom property. But the performance is very poor ... in some tablets, I noticed a horizontal white line (height about 3 pixels) during the animation, in another device for smartphones it went only to slow down (not slow duration, but flickering).
I found a way to fix this if I set valueFrom and valueTo to fit the size of the view, but it is not common and must be from 0 to 1 to be common to all views
Understand if someone can help me or say if there is another way to implement on Android version 14 and higher.
Thanks.
source share