[英]Speed up splash screen imageView creation
我为我的应用程序创建了一个简单的启动屏幕。 它基本上由一个ImageView和两个textView组成。 imageView加载2048x1365的背景图像。 我遇到的问题是,启动该应用程序时,在渲染视图时出现黑屏(android默认)大约一秒钟。 我假设这与加载图像所需的时间有关。 有什么方法可以加快速度,使其在呈现初始屏幕时直接跳入初始屏幕,而不会出现第二个左右的黑色屏幕。
这是视图代码。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/imageView"
android:layout_centerVertical="true"
android:layout_alignParentRight="false"
android:layout_alignParentEnd="false"
android:src="@drawable/backdrop"
android:scaleType="centerCrop" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="APP NAME"
android:id="@+id/programSpecific"
android:layout_below="@+id/imageView2"
android:layout_centerHorizontal="true"
android:textSize="30sp"
android:layout_marginTop="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="COMPANY NAME"
android:id="@+id/textView"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:textSize="40dp" />
</RelativeLayout>
</RelativeLayout>
和班级
package co.uk.jameskrawczyk.testsplash;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.Handler;
import android.widget.TextView;
public class splashscreen extends Activity {
/** Duration of wait **/
private final int SPLASH_DISPLAY_LENGTH = 4000;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.spashscreen);
//Define font for use
Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/sourcesanspro.otf");
((TextView) findViewById(R.id.textView)).setTypeface(typeface);
((TextView) findViewById(R.id.programSpecific)).setTypeface(typeface);
/* New Handler to start the Menu-Activity
* and close this Splash-Screen after some seconds.*/
new Handler().postDelayed(new Runnable(){
@Override
public void run() {
/* Create an Intent that will start the Menu-Activity. */
Intent mainIntent = new Intent(splashscreen.this,landingScreenClass.class);
splashscreen.this.startActivity(mainIntent);
splashscreen.this.finish();
}
}, SPLASH_DISPLAY_LENGTH);
}
}
您可以设置窗口背景色。 它将替换为黑色。 只需在您的应用主题中添加以下行:
<item name="android:windowBackground">@color/app_background</item>
但我建议不要使用高细节的启动画面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.