我为我的应用创建了一个简单的启动画面。它基本上由一个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);
}
}
答案 0 :(得分:2)
您可以设置窗口背景颜色。它将取代黑色。只需在您的应用主题中添加此行:
<item name="android:windowBackground">@color/app_background</item>
但我建议不要使用高度详细的闪屏。