0
我試圖使用ObjectAnimator
沿着path
移動ImageView
。我正面臨着NPE
。這是我正在嘗試的代碼。無法使用ObjectAnimator沿着Android中的路徑移動和設置ImageView的動畫效果
path = new Path();
path.moveTo((float)(maxX/2)+(maxX/4),maxY/4);
path.quadTo((float)(maxX/2)+(maxX/4),maxY/4, (float)(maxX/2)+(maxX/4)+30,maxY/2);
ObjectAnimator animator = new ObjectAnimator();
animator.ofFloat(img,View.X,View.Y,path);
animator.setDuration(1000);
animator.setStartDelay(600);
animator.start();
的exception
是:
Caused by: java.lang.NullPointerException: Attempt to get length of null array
at android.animation.ValueAnimator.initAnimation(ValueAnimator.java:534)
at android.animation.ObjectAnimator.initAnimation(ObjectAnimator.java:880)
at android.animation.ValueAnimator.setCurrentFraction(ValueAnimator.java:610)
at android.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:589)
at android.animation.ValueAnimator.start(ValueAnimator.java:1106)
at android.animation.ValueAnimator.start(ValueAnimator.java:1117)
at android.animation.ObjectAnimator.start(ObjectAnimator.java:852)
at com.example.user.curveanimation.MainActivity.onCreate(MainActivity.java:48)
at android.app.Activity.performCreate(Activity.java:6251)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2403)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2510)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5461)
at java.lang.reflect.Method.invoke(Native Method)
如果有什麼事我做錯了,有人可以幫我通過路徑動畫。 SOmebody,請幫助!謝謝。