在setContentView运行时显示初始屏幕

时间:2019-07-11 18:25:12

标签: android

我目前正在尝试减少应用程序的冷启动时间,并且我已经意识到大部分时间都花在setContentView上(2.6秒中约2秒)。

我想进一步减少这种情况,而我正在考虑的一种方法是在setContentView执行其工作时显示初始屏幕。但是,这似乎有点违反直觉,因为(我认为)setContentView在UI线程上运行,因此不会显示与setContentView的初始屏幕冲突吗?

此外,我对为什么setContentView花这么长时间考虑我的XML感到困惑。如果可以直接解决setContentView的加载时间,那当然是另一种选择。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:id="@+id/main_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        app:layout_scrollFlags="scroll|enterAlways">

    </android.support.v7.widget.Toolbar>

    <android.support.v4.widget.DrawerLayout
        android:layout_width="match_parent"
        android:id="@+id/drawer_layout"
        android:layout_height="match_parent">
        <!-- The main content view -->
        <FrameLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/drawer_layout_content">
        </FrameLayout>

        <!-- The navigation drawer -->
        <android.support.design.widget.NavigationView
            android:id="@+id/navigation_drawer"
            android:layout_width="320dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:choiceMode="singleChoice"
            app:itemIconTint="@color/selector_dark_text"
            android:background="@drawable/dark_background"
            app:itemBackground="@drawable/selector_dark"
            app:itemTextColor="@color/selector_dark_text"
            app:menu="@menu/drawer"/>
    </android.support.v4.widget.DrawerLayout>
</LinearLayout>

0 个答案:

没有答案
相关问题