Android,如何知道动画已经完成?

发布于 2024-12-08 10:25:09 字数 541 浏览 0 评论 0原文

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

@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,注释),当我运行应用程序并单击按钮时,动画将会播放。但如果我取消注释它,因为快速过渡动画不会显示。 我如何通知动画已完成? 谢谢

In my project i have a button. when user clicks on it, it shows and animation after that should load another activity.

@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;
        }

    }

according to above code(startActivity, commented), when I run the application and click on the button, animation will play. but if i uncomment it because of fast transition animation doesn't show.
How can i inform that animation is finished?
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情释 2024-12-15 10:25:09

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

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

    }
});

On your animation object call this code:

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

    }
});
2024-12-15 10:25:09

Kotlin 2023 更新。以下是拉胡尔卡皮尔的回答。

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)

Update 2023 in Kotlin. Following Rahulkapil answer.

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文