Android动画有一段时间限制 [英] Android animation for some time limit

查看:114
本文介绍了Android动画有一段时间限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个具有启动画面的Android应用程序,我想给它一个动画。我成功地添加了动画,但我想要的是5秒后下一个意图应该打开。但现在它直接打开第二个意图并且启动画面没有运行。我的发布活动是启动画面。下面是动画和启动画面的代码。

Blink.xml

I'm making an android app which has a splash screen and I want to give an animation t it. I successfully added animation to it but what i want is after 5 seconds next intent should open. but now it directly opens the second intent and splash screen is not running. my launch activity is splash screen. below is the code for animation and splash screen.
Blink.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <alpha android:fromAlpha="0.0"

        android:toAlpha="1.0"

        android:interpolator="@android:anim/accelerate_interpolator"

        android:duration="10000"

        android:repeatMode="reverse"

        android:repeatCount="infinite"/>
</set>





Splashscreen.java



Splashscreen.java

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash_screen);
        blink(new View(getApplicationContext()));

    }

 public void blink(View view){
        ImageView image = (ImageView)findViewById(R.id.imageView);
        Animation animation1 = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.blink);
        image.startAnimation(animation1);
        Intent mainIntent=new Intent(SplashScreen.this,MainActivity.class);
        mainIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(mainIntent);
        finish();
    }

推荐答案

您需要添加动画监听器 [ ^ ]到你的活动。

onAnimationEnd() [ ^ ]你可以开始你的新意图。

像这样的东西,

you need to add an Animation Listener[^] to your activity.
And the onAnimationEnd()[^] you can start your new intent.
Something like this,
public void blink(View view){
        ImageView image = (ImageView)findViewById(R.id.imageView);
        Animation animation1 = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.blink);
        animation1.setAnimationListener(new AnimationListener() {
            public void onAnimationStart(Animation animation) {}
            public void onAnimationRepeat(Animation animation) {}
            public void onAnimationEnd(Animation animation) {
                       // your intent to start
            }
        }    
image.startAnimation(animation1);
        finish();
    }





-KR



-KR


这篇关于Android动画有一段时间限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆