NineOldAndroids animation not working on API>10

北战南征 提交于 2019-12-01 13:22:26

I had an issue with this library on devices API < 10, which gave the same stacktrace. Given i was using the source code of NineOldAndroids i decided to investigate the problem inside the library.

After some tests i noticed that this error occurs because the lib tries to invoke some methods that doesn't exists on the view (since its an old API level). Searching a bit more i found the AnimatorProxy class which has a static method called "wrap". This method is used to encapsulate View objects in older Android versions emulating the presence of some animation methods as such setScaleX/Y, setTransalationX/Y.

To fix the problem i had to open the ObjectAnimator class and search for all occurrences of this line (In my library code i found 4 occurrences):

mTarget = target;

Inside that class i created the following method:

private void setTarget(Object obj) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB && obj instanceof View) {
        mTarget = AnimatorProxy.wrap((View) obj);
    } else {
        mTarget = obj;
    }
}

And replaced the line above with:

setTarget(target);

Don't know if it can fix your problem since you said that it occurs on API 10+ (the opposite of mine) but its a good point to start.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!