Android启动画面错误

时间:2018-02-04 13:43:49

标签: java android android-layout android-studio android-imageview

我是Android编程的新手。我试图制作一个闪屏,我有两个不同的图像......一个用于背景,另一个用于徽标......两个图像都在单独的图像视图中。图像的大小分别约为23kb和3kb。但是当我运行应用程序时。它显示处理器可能正在执行其他工作的错误。跳过88帧。这完全跳过了闪屏并直接进入主要活动。请任何人都可以帮我解决问题。

2 个答案:

答案 0 :(得分:1)

在android中实现启动画面的最佳方法是将启动画面的背景作为活动的主题背景。 请查看本文以获取实施指南https://www.bignerdranch.com/blog/splash-screens-the-right-way/

答案 1 :(得分:0)

在父级中设置背景图片并将孩子徽标图像设为... 像这样: -

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/backgroundImage"
    tools:context="xyz.xyz.com.xyz.activity.SplashActivity">

    <ImageView
        android:id="@+id/logoImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:layout_gravity="center"
        android:src="@drawable/logoImage" />
</RelativeLayout>

在java代码中使用: -

public class SplashActivity extends AppCompatActivity {

    private long ms = 0;
    private long splashTime = 2000;
    private boolean splashActive = true;
    private boolean paused = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

            Thread mythread = new Thread() {
                public void run() {
                    try {
                        while (splashActive && ms < splashTime) {
                            if (!paused)
                                ms = ms + 100;
                            sleep(100);
                        }
                    } catch (Exception e) {
                    }
                    finally
                    {
                        System.out.println("reached");
                        Intent intent = new Intent(SplashActivity.this, LoginActivity.class);
                        System.out.println("reached1");
                        startActivity(intent);
                        System.out.println("reached2");
                        finish();
                        System.out.println("reached3");
                    }
                }
            };
            mythread.start();

}
相关问题