使用ObjectAnimator的空指针


ObjectAnimator animator = new ObjectAnimator();
animator.setDuration(300);
animator.ofFloat(mBottomContainer, "scaleX", 0.0f, 1.0f);
animator.setInterpolator(new AccelerateInterpolator());
animator.start();

程序会报出空指针。因为animator.ofFloat(mBottomContainer, "scaleX", 0.0f, 1.0f);这个是ObjectAnimator类的静态方法,在方法中会重新创建一个ObjectAnimator的对象,所以导致animator没有设置上Target,顾报出空指针。
解决

ObjectAnimator animator = ObjectAnimator.ofFloat(mBottomContainer, "scaleX", 0.0f, 1.0f);
animator.setDuration(300);
animator.setInterpolator(new AccelerateInterpolator());
animator.start();




 

你可能感兴趣的:(android错误)