【问题标题】:Application is not responding while using animation on Imageview在 Imageview 上使用动画时应用程序没有响应
【发布时间】:2020-06-27 13:52:38
【问题描述】:

我有一个图像视图,并使用YoYo 无限地为图像设置动画。单击此图像视图时,我需要开始一个新活动AnimalIntroducer。我可以点击这个动画按钮开始新的活动AnimalIntroducer。但是,当我回到我的HomeActivity 时单击AnimalIntroducer 活动中的后退按钮时,imageview 上的此动画停止,并且按钮单击变得无响应并显示application is not responding。我必须在后台线程中运行动画吗?如果是这样,我该怎么做?

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home_activity);

        hangingMonkeyImageView = findViewById(R.id.monkey_hanging_image_view);

        YoYo.with(Techniques.Bounce)
                .duration(1000)
                .repeat(-1)
                .playOn(hangingMonkeyImageView);

        hangingMonkeyImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(HomeActivity.this,AnimalIntroducer.class);
                startActivity(intent);

            }
        });

    }

【问题讨论】:

    标签: android memory-leaks android-animation


    【解决方案1】:

    我建议你在用户导航到第二个活动时停止动画,然后在 HomeActivity 的 onResume() 方法中重新启动动画。

    如果您想了解更多信息,请查看Android Activity Lifecycle

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-01
      • 2019-02-15
      • 2023-03-28
      • 2017-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多