gpt4 book ai didi

android - SplashScreen - 关闭时间

转载 作者:行者123 更新时间:2023-11-30 01:44:15 26 4
gpt4 key购买 nike

我使用 Internet 代码在我的应用程序中部署了启动画面,一切正常但无法为此 Activity 设置时间关闭并打开主应用程序可以帮助我。我尝试了处理程序的形状,但在一段时间后关闭了应用程序。

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();
}
}

最佳答案

看看这个教程 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 方法中开始你的下一个 Activity

关于android - SplashScreen - 关闭时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33967981/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com