我有一個測試活動,它應該做很簡單的任務:膨脹視圖,並用ObjectAnimator在屏幕上移動它。ActionBarSherlock和Android的ObjectAnimator上的NineOldAndroids之間的區別<11
如果我使用NineOldAndroids庫,它可以與所有設備(OS 2.2+ - OS4.2)完美兼容。但是,如果我將庫更改爲ActionBarSherlock(它假設內部具有相同的NineOldAndroid庫),它適用於OS 3.x及更高版本,但它不適用於2.2和2.3設備。在這種情況下,它無法找到該屬性並拋出空指針異常(如下所示)。
任何人都有同樣的問題?有沒有解決方法,或者我實際上使用了兩個庫(NineOldAndroids和ActionBarSherlock)來解決問題?
這裏是TestsActivity
:
public class TestActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
RelativeLayout mainLayout = (RelativeLayout) findViewById(R.id.main_layout);
View testView = getLayoutInflater().inflate(R.layout.object_holder, null);
mainLayout.addView(testView);
AnimatorSet set = new AnimatorSet();
set.playTogether(
ObjectAnimator.ofFloat(testView, "translationX", 100),
ObjectAnimator.ofFloat(testView, "translationY", 100)
);
set.setDuration(0).start();
}
}
(同樣的事情發生,如果我改變「translationX」與「×」。)
這裏是個例外(它的發生只是如果我使用的庫actionBarSherlock在2.2和2.3的設備):
05-16 13:24:53.662: E/PropertyValuesHolder(2007): Couldn't find setter property translationX for RelativeLayout with value type float
05-16 13:24:53.662: E/PropertyValuesHolder(2007): RelativeLayout - Couldn't find no-arg method for property translationX: java.lang.NoSuchMethodException: getTranslationX
05-16 13:24:53.662: D/AndroidRuntime(2007): Shutting down VM
05-16 13:24:53.662: W/dalvikvm(2007): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0)
05-16 13:24:53.672: E/AndroidRuntime(2007): FATAL EXCEPTION: main
05-16 13:24:53.672: E/AndroidRuntime(2007): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.testanimator/com.example.testanimator.TestActivity}: java.lang.NullPointerException
05-16 13:24:53.672: E/AndroidRuntime(2007): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1821)
05-16 13:24:53.672: E/AndroidRuntime(2007): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1842)
05-16 13:24:53.672: E/AndroidRuntime(2007): at android.app.ActivityThread.access$1500(ActivityThread.java:132)
05-16 13:24:53.672: E/AndroidRuntime(2007): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1038)
05-16 13:24:53.672: E/AndroidRuntime(2007): at android.os.Handler.dispatchMessage(Handler.java:99)
05-16 13:24:53.672: E/AndroidRuntime(2007): at android.os.Looper.loop(Looper.java:150)
05-16 13:24:53.672: E/AndroidRuntime(2007): at android.app.ActivityThread.main(ActivityThread.java:4263)
05-16 13:24:53.672: E/AndroidRuntime(2007): at java.lang.reflect.Method.invokeNative(Native Method)
05-16 13:24:53.672: E/AndroidRuntime(2007): at java.lang.reflect.Method.invoke(Method.java:507)
05-16 13:24:53.672: E/AndroidRuntime(2007): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-16 13:24:53.672: E/AndroidRuntime(2007): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-16 13:24:53.672: E/AndroidRuntime(2007): at dalvik.system.NativeStart.main(Native Method)
05-16 13:24:53.672: E/AndroidRuntime(2007): Caused by: java.lang.NullPointerException
05-16 13:24:53.672: E/AndroidRuntime(2007): at com.actionbarsherlock.internal.nineoldandroids.animation.PropertyValuesHolder.setupSetterAndGetter(PropertyValuesHolder.java:515)
05-16 13:24:53.672: E/AndroidRuntime(2007): at com.actionbarsherlock.internal.nineoldandroids.animation.ObjectAnimator.initAnimation(ObjectAnimator.java:386)
05-16 13:24:53.672: E/AndroidRuntime(2007): at com.actionbarsherlock.internal.nineoldandroids.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:539)
05-16 13:24:53.672: E/AndroidRuntime(2007): at com.actionbarsherlock.internal.nineoldandroids.animation.ValueAnimator.start(ValueAnimator.java:929)
05-16 13:24:53.672: E/AndroidRuntime(2007): at com.actionbarsherlock.internal.nineoldandroids.animation.ValueAnimator.start(ValueAnimator.java:952)
05-16 13:24:53.672: E/AndroidRuntime(2007): at com.actionbarsherlock.internal.nineoldandroids.animation.ObjectAnimator.start(ObjectAnimator.java:364)
05-16 13:24:53.672: E/AndroidRuntime(2007): at com.actionbarsherlock.internal.nineoldandroids.animation.AnimatorSet.start(AnimatorSet.java:501)
05-16 13:24:53.672: E/AndroidRuntime(2007): at com.example.testanimator.TestActivity.onCreate(TestActivity.java:30)
05-16 13:24:53.672: E/AndroidRuntime(2007): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
05-16 13:24:53.672: E/AndroidRuntime(2007): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1785)
05-16 13:24:53.672: E/AndroidRuntime(2007): ... 11 more