Screen white when navigate to destination fragment using navigation architecture component Android

Viewed 1292

I'm using a navigation graph to navigate from fragment A to B with animation slide up duration =0.4s, but while 0.4s before fragment B appears, fragment A becomes a white screen, not keep state data and UI before.

Update: I tried to clone a sample project with some background color config at all screen. And I found that when navigating to fragment B, fragment A is removed and replaced by fragment B, so the main activity layout contains fragment is visible with the background color of it during 0.4s.

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
        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="#F1E78C"
        tools:context="com.myricseptember.countryfact.ui.MainActivity">

    <fragment
            android:id="@+id/navigationHostFragment"
            android:name="androidx.navigation.fragment.NavHostFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:defaultNavHost="true"
            app:navGraph="@navigation/countryfact_navigation_graph"/>

</android.support.constraint.ConstraintLayout>

fragment_country_list.xml

    <?xml version="1.0" encoding="utf-8"?>
<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="#123456">

    <android.support.v7.widget.RecyclerView
            android:id="@+id/countryRecyclerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            app:layoutManager="android.support.v7.widget.LinearLayoutManager"
            tools:listitem="@layout/layout_list_item" />
</RelativeLayout>

fragment_country_detail.xml

    <?xml version="1.0" encoding="utf-8"?>

<ScrollView 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="#CAEACB">


    <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

    </android.support.constraint.ConstraintLayout>
</ScrollView>

countryfact_navigation_graph.xml

<?xml version="1.0" encoding="utf-8"?>
<navigation 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:id="@+id/countryfact_navigation_graph"
        app:startDestination="@id/countryListFragment">

    <fragment
            android:id="@+id/countryListFragment"
            android:name="com.myricseptember.countryfact.ui.list.CountryListFragment"
            android:label="Country Fact"
            tools:layout="@layout/fragment_country_list">
        <action
                android:id="@+id/action_countryListFragment_to_countryDetailsFragment"
                app:destination="@id/countryDetailsFragment"
                app:enterAnim="@anim/slide_up"
                app:popExitAnim="@anim/slide_down" />
    </fragment>
    <fragment
            android:id="@+id/countryDetailsFragment"
            android:name="com.myricseptember.countryfact.ui.details.CountryDetailsFragment"
            android:label="CountryDetailsFragment"
            tools:layout="@layout/fragment_country_details" />
    />
</navigation>

And video record of issues:

=> How to custom navigation add fragment (not remove-replace) or custom handle remove A after fragment B transaction up?

0 Answers
Related