我正在使用导航图从片段A导航到片段B,动画滑动持续时间= 0.4s,但是虽然片段B出现前0.4s,片段A却变成白屏,而不是之前保留状态数据和UI。
更新: 我试图在所有屏幕上克隆带有一些背景颜色配置的示例项目。而且我发现,导航到片段B时,片段A被删除并被片段B取代,因此主要活动布局包含的片段在0.4秒内可见,其背景颜色为
。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>
=>如何在片段B事务完成后如何自定义导航添加片段(而不是移除-替换)或自定义句柄移除A?