且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何实现在Android的启动画面

更新时间:2023-01-26 09:56:42

基本上,你要找的是一个闪屏,显示您的图片,然后淡出。主要活动的屏幕,然后消失。所以你可以做的是创建一个活动的启动画面,然后另外一个你可能想要呼叫的主要活动。这将是您的闪屏的活动。

Basically, what you're looking for is a Splash screen which shows your image and then fades out. A main activity's screen then fades in. So what you could do is create an activity for the Splash screen and then another one for the main activity you might want to call. This would be your Splash Screen activity.

public class SplashScreen extends Activity {
private static final int SPLASH_DISPLAY_TIME = 4000; // splash screen delay time

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);

    new Handler().postDelayed(new Runnable() {
        public void run() {

            Intent intent = new Intent();
            intent.setClass(Splash.this, NextActivity.class);

            Splash.this.startActivity(intent);
            Splash.this.finish();

            // transition from splash to main menu
            overridePendingTransition(R.animate.activityfadein,
                    R.animate.splashfadeout);

        }
    }, SPLASH_DISPLAY_TIME);
}

NextActivity是要褪色的,并取代它的任何活动。对于动画,你需要在你的资源创建一个文件夹,名为有生两个XML文件。 这里是splashfadeout.xml文件

NextActivity is any activity that you want to fade in and take its place. For the animations you would need to create the two xml files in a folder called animate in your resources. Here is the splashfadeout.xml file

<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator"
android:zAdjustment="top" android:fromAlpha="1.0" android:toAlpha="0.0"
android:duration="4000" />

这将是activityfadein.xml文件

This would be the activityfadein.xml file

<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="2000" />

这些文件基本上是让你的活动淡入淡出

These files basically make your activities fade in and out