2015-11-28 3 views
1

Я развернул заставку в своем приложении с кодом в Интернете, все работает, но не может установить время для закрытия этого мероприятия и открыть основное приложение, которое могло бы мне помочь. Я пробовал форму обработчика, но закрыл приложение после времени.SplashScreen - Время для закрытия

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

ответ

1

Взгляните на этот учебник http://www.androidhive.info/2013/07/how-to-implement-android-splash-screen-2/

Использование Handler

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 это время в миллисекундах. Начните свою следующую деятельность внутри метода прогона.

+0

Спасибо, что помогли мне работать сейчас. ;) –

Смежные вопросы