Android应用程序中的启动画面

AAB*_*AAB 4 android

我正在修改一个开源应用程序,并希望为它添加一个启动画面,有人可以帮助我吗?

当应用程序启动时,黑屏将显示2到3秒,然后应用程序出现....在代码中,活动main.xml已启动,我已阅读一些论坛,应该创建splash.xml文件并使用线程启动活动和主要活动的帮助应该并行执行.这是正确的方法......?

#
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        instance = this;
        setContentView(R.layout.main);
Run Code Online (Sandbox Code Playgroud) #

我不可能修改main.xml并将图像(splash)放在main.xml中,以便从那里出现吗?

Mau*_*k J 16

使用SplashScreen类作为下

public class Splashscreen extends Activity {

private static final int SPLASH_DISPLAY_TIME = 3000; /* 3 seconds */

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

    new Handler().postDelayed(new Runnable() {

        public void run() {

            Intent mainIntent = new Intent(Splashscreen.this,
                    MainActivity.class);
            Splashscreen.this.startActivity(mainIntent);

            Splashscreen.this.finish();
            overridePendingTransition(R.anim.mainfadein,
                    R.anim.splashfadeout);
        }
    }, SPLASH_DISPLAY_TIME);
}
Run Code Online (Sandbox Code Playgroud)

}

**在res-> anim文件夹中添加mainfadein.xml和splashfadeout.xml

mainfadein.xml**

    <?xml version="1.0" encoding="utf-8"?>
<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="1000">
</alpha>
Run Code Online (Sandbox Code Playgroud)

splashfadeout.xml

<?xml version="1.0" encoding="utf-8"?>
<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="1000" >
</alpha>
Run Code Online (Sandbox Code Playgroud)

并添加splash.xml只需添加一个ImageView并将其背景设置为屏幕并在布局中添加urchoice的图像

并将Splashscreen类设为Launcher,并将所有其他类设置为清单文件中的HOME