Android,我怎么知道动画完成了?

dldeef67  于 2023-05-21  发布在  Android
关注(0)|答案(2)|浏览(105)

在我的项目中,我有一个按钮。当用户点击它时,它会显示动画,之后应该加载另一个活动。

@Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btnReadPage:
                startAnimation();
                //stopAnimation();
                //Toast.makeText(this, "Read Page Clicked", Toast.LENGTH_SHORT).show();
                //startActivity(new Intent(this, ReadPage.class));
                return;
        }

    }

根据上面的代码(startActivity,已注解),当我运行应用程序并单击按钮时,将播放动画。但如果我取消注解,因为快速过渡动画不显示。如何通知动画已完成?谢谢

gdrx4gfi

gdrx4gfi1#

在动画对象上调用以下代码:

am1.setAnimationListener(new AnimationListener() {    
    @Override
    public void onAnimationStart(Animation animation) {  
        // TODO Auto-generated method stub
    }

    @Override
    public void onAnimationRepeat(Animation animation) {
        // TODO Auto-generated method stub
    }

    @Override
    public void onAnimationEnd(Animation animation) {
        // Pass the Intent to switch to other Activity

    }
});
z3yyvxxp

z3yyvxxp2#

在Kotlin中更新2023。”Rahulkapil回答。

val animation = AnimationUtils.loadAnimation(requireContext(), R.anim.fade_in)

animation.fillAfter = true
animation.duration = 2000

animation.setAnimationListener(object : AnimationListener {
    override fun onAnimationStart(animation: Animation) {
        Log.d("////", "onAnimationStart")
    }

    override fun onAnimationRepeat(animation: Animation) {
        Log.d("////", "onAnimationRepeat")
    }

    override fun onAnimationEnd(animation: Animation) {
        Log.d("////", "onAnimationEnd")
        // Pass the Intent to switch to other Activity
    }
})
binding.myTextView.startAnimation(animation)

相关问题