android 闪屏-关闭时间

ivqmmu1c  于 2022-12-02  发布在  Android
关注(0)|答案(1)|浏览(90)

我在我的应用程序中部署了一个闪屏与互联网代码,一切都在工作,但无法设置此活动的时间关闭和打开主应用程序可以帮助我。我已经尝试了处理程序的形状,但关闭应用程序后的时间。

package com.packpage.application;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextView;

import com.packpage.application.FontelloTextView;
import com.packpage.application.KenBurnsView;

public class SplashScreensActivity extends Activity {

    public static final String SPLASH_SCREEN_OPTION = "com.packpage.application.SplashScreensActivity";
    public static final String SPLASH_SCREEN_OPTION_1 = "Option 1";
    public static final String SPLASH_SCREEN_OPTION_2 = "Option 2";
    public static final String SPLASH_SCREEN_OPTION_3 = "Option 3";

    private KenBurnsView mKenBurns;
    private FontelloTextView mLogo;
    private TextView welcomeText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().requestFeature(Window.FEATURE_NO_TITLE); //Removing ActionBar
        setContentView(R.layout.activity_splash_screen);

        mKenBurns = (KenBurnsView) findViewById(R.id.ken_burns_images);
        mLogo = (FontelloTextView) findViewById(R.id.logo);
        welcomeText = (TextView) findViewById(R.id.welcome_text);
        mKenBurns.setImageResource(R.drawable.splash_screen_background);

        String category = SPLASH_SCREEN_OPTION_1;
        Bundle extras = getIntent().getExtras();
        if (extras != null && extras.containsKey(SPLASH_SCREEN_OPTION)) {
            category = extras.getString(SPLASH_SCREEN_OPTION, SPLASH_SCREEN_OPTION_1);
        }
        setAnimation(category);
    }

    /** Animation depends on category.
     * */
    private void setAnimation(String category) {
        if (category.equals(SPLASH_SCREEN_OPTION_1)) {
            animation1();
        } else if (category.equals(SPLASH_SCREEN_OPTION_2)) {
            animation2();
        } else if (category.equals(SPLASH_SCREEN_OPTION_3)) {
            animation2();
            animation3();
        }
    }

    private void animation1() {
        ObjectAnimator scaleXAnimation = ObjectAnimator.ofFloat(mLogo, "scaleX", 5.0F, 1.0F);
        scaleXAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
        scaleXAnimation.setDuration(1200);
        ObjectAnimator scaleYAnimation = ObjectAnimator.ofFloat(mLogo, "scaleY", 5.0F, 1.0F);
        scaleYAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
        scaleYAnimation.setDuration(1200);
        ObjectAnimator alphaAnimation = ObjectAnimator.ofFloat(mLogo, "alpha", 0.0F, 1.0F);
        alphaAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
        alphaAnimation.setDuration(1200);
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.play(scaleXAnimation).with(scaleYAnimation).with(alphaAnimation);
        animatorSet.setStartDelay(500);
        animatorSet.start();
    }

    private void animation2() {
        mLogo.setAlpha(1.0F);
        Animation anim = AnimationUtils.loadAnimation(this, R.anim.translate_top_to_center);
        mLogo.startAnimation(anim);
    }

    private void animation3() {
        ObjectAnimator alphaAnimation = ObjectAnimator.ofFloat(welcomeText, "alpha", 0.0F, 1.0F);
        alphaAnimation.setStartDelay(1700);
        alphaAnimation.setDuration(500);
        alphaAnimation.start();
    }
}
iaqfqrcu

iaqfqrcu1#

看一看这个教程http://www.androidhive.info/2013/07/how-to-implement-android-splash-screen-2/
使用处理程序

new Handler().postDelayed(new Runnable() {
 
            /*
             * Showing splash screen with a timer. This will be useful when you
             * want to show case your app logo / company
             */
 
            @Override
            public void run() {
                // This method will be executed once the timer is over
                // Start your app main activity
                Intent i = new Intent(SplashScreen.this, MainActivity.class);
                startActivity(i);
 
                // close this activity
                finish();
            }
        }, SPLASH_TIME_OUT);

SPLASH_TIME_OUT是以毫秒为单位时间在run方法内启动下一个活动

相关问题