AppCompat v22: Links to new interpolators via XML

I am trying to use the new interpolators available in the v22 support library (FastOutLinearIn, etc.). More specifically, I would like to reference them via XML.

I tried using @android: interpolator / fast_out_linear_in, but LINT tells me that the v21 +. I've tried digging elsewhere and haven't found anything that looks like it might help.

I also tried to create custom interpolators like this: (in my_linear_out_slow_in.xml)

<?xml version="1.0" encoding="utf-8"?>
<linearOutSlowInInterpolator />

      

and

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.view.animation.LinearOutSlowInInterpolator          
   xmlns:android="http://schemas.android.com/apk/res/android" />

      

but they don't work in Lollipop or previous versions: activity transitions are no longer displayed, leaving the app in a state where the old activity is still visible but not responding because, I suppose, the new activity is considered active, but isn't rendered. Before the upgrade, when v21 + styles were using new (incompatible) interpolators, they worked great.

+3


source to share


1 answer


Unfortunately, it is not possible to use the design support library libraries in the xml. It has to do with how AnimationUtils

the creation of the interpolator handles.

Taken from Gingerbread source (API 9) http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.3.2_r1/android/view/animation/AnimationUtils.java? av = f

 private static Interpolator createInterpolatorFromXml(Context c, XmlPullParser parser)
        throws XmlPullParserException, IOException {

    Interpolator interpolator = null;

    // Make sure we are on a start tag.
    int type;
    int depth = parser.getDepth();

    while (((type=parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth)
           && type != XmlPullParser.END_DOCUMENT) {

        if (type != XmlPullParser.START_TAG) {
            continue;
        }

        AttributeSet attrs = Xml.asAttributeSet(parser);

        String  name = parser.getName();


        if (name.equals("linearInterpolator")) {
            interpolator = new LinearInterpolator(c, attrs);
        } else if (name.equals("accelerateInterpolator")) {
            interpolator = new AccelerateInterpolator(c, attrs);
        } else if (name.equals("decelerateInterpolator")) {
            interpolator = new DecelerateInterpolator(c, attrs);
        }  else if (name.equals("accelerateDecelerateInterpolator")) {
            interpolator = new AccelerateDecelerateInterpolator(c, attrs);
        }  else if (name.equals("cycleInterpolator")) {
            interpolator = new CycleInterpolator(c, attrs);
        } else if (name.equals("anticipateInterpolator")) {
            interpolator = new AnticipateInterpolator(c, attrs);
        } else if (name.equals("overshootInterpolator")) {
            interpolator = new OvershootInterpolator(c, attrs);
        } else if (name.equals("anticipateOvershootInterpolator")) {
            interpolator = new AnticipateOvershootInterpolator(c, attrs);
        } else if (name.equals("bounceInterpolator")) {
            interpolator = new BounceInterpolator(c, attrs);
        } else {
            throw new RuntimeException("Unknown interpolator name: " + parser.getName());
        }

    }

    return interpolator;

}

      



They follow the same code signal, but a new Interpolator has been added to the lollipop PathInterpolator

, which is the "base class" of all new interpolators.

You can use new interpolators, however they must be in the xml version directory. One of the challenges would be to create your own "AnimationUtils", however that would mean including another method + of your R.anim. * Whenever you find a method that takes an id for an animation.

+2


source







All Articles