【问题标题】:Speed up splash screen imageView creation加速启动画面 imageView 创建
【发布时间】:2015-01-10 01:30:54
【问题描述】:

我为我的应用创建了一个简单的启动画面。它基本上由一个 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);
    }
}

【问题讨论】:

    标签: android image optimization splash-screen


    【解决方案1】:

    您可以设置窗口背景颜色。它将取代黑色。只需在您的应用主题中添加这一行:

        <item name="android:windowBackground">@color/app_background</item>
    

    但我建议不要使用非常详细的启动画面。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-04
      • 2023-03-20
      • 2022-07-01
      • 2020-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多