NineOldAndroids animation not working on API>10

后端 未结 1 1171
甜味超标
甜味超标 2021-01-16 05:03

I am using NineOldAndroid library to perform animations. The animations work fine for API<=10. But for API>10 the app force closes. This is my code:

1条回答
  •  时光取名叫无心
    2021-01-16 05: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.

    0 讨论(0)
提交回复
热议问题