开发者社区> 问答> 正文

为什么把ObjectAnimator设置成成员变量,调用start() 报错呢 400 请求报错 

package com.example.azezer0.demoanimatior;

import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {
    private ImageView iv;

    private ObjectAnimator checkAnimator;
    private PropertyValuesHolder propertyValueScaleX;
    private PropertyValuesHolder propertyValueScaleY;
    private PropertyValuesHolder propertyValueScaleAlpha;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        iv = (ImageView) findViewById(R.id.iv);
        initAnimator();
        iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                checkAnimator.start();
            }
        });

    }

    private void initAnimator() {
        checkAnimator = new ObjectAnimator();
        propertyValueScaleX = PropertyValuesHolder.ofFloat("scaleX", 0.0f, 1.0f);
        propertyValueScaleY = PropertyValuesHolder.ofFloat("scaleY", 0.0f, 1.0f);
        propertyValueScaleAlpha = PropertyValuesHolder.ofFloat("alpha", 0.0f, 1.0f);
        checkAnimator.ofPropertyValuesHolder(iv, propertyValueScaleAlpha, propertyValueScaleX, propertyValueScaleY).setDuration(2000).start();
    }


}
进入页面时,是正常播放的,为什么触动点击事件,就报错。

展开
收起
kun坤 2020-05-28 16:04:32 838 0
1 条回答
写回答
取消 提交回答
  • Process: com.example.azezer0.demoanimatior, PID: 4361 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.azezer0.demoanimatior.MainActivity$1.onClick(MainActivity.java:33) at android.view.View.performClick(View.java:5198) at android.view.View$PerformClick.run(View.java:21147) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)######搞定了######是怎么回事

    2020-05-29 13:05:57
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
建立联系方法之一 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载

相关实验场景

更多