FragmentTransacation with slide in/out animation on >4 performance
Asked Answered
E

1

6

I'm trying to implement fragment transaction with slide in/out animation. I'm developing on minimum 14 sdk so ObjectAnimator is the only option for me (is there any other way? translate animation is not available as I understand).

The Code is very simple:

AnimationView.java - wrapper 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);
}
}

Slide in & out xml's

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

Animations works perfect, as you can see I used custom property yFraction. But performance are very bad... in some tablets I noticed a horizontal white line (around 3 px height) during the animation, in other smartphone device it went just to slow (not duration slow but Flickering).

I found a way to fix it if I set valueFrom & valueTo to fit the view dimension, but it's not generic and need to be 0 to 1 to be generic for all views

Would appreciate if some can help me or tell me if there's another way to implement on android 14 and up.

Thanks.

Elysian answered 1/8, 2013 at 6:41 Comment(0)
L
-4

Try this:

if (mLastMenuWeight > mMenuWeight) {
transaction.setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
}else{transaction.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left);}
Lynellelynett answered 7/1, 2014 at 8:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.