![](/img/trans.png)
[英]Add enter animation to start destination in android navigation component
[英]Android Navigation Component with Retained Fragments and enter animation
我正在嘗試將導航組件與保留的Fragment和Enter動畫一起使用。 該片段將與預期的動畫一起出現。 旋轉設備時,出現以下崩潰:
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
我可以通過刪除輸入動畫(從導航圖)或不保留片段來解決此問題。
有誰知道如何解決這個問題,因為我希望保留動畫。
這是我的onCreate:
private var binding: FragmentDemoBinding? = null
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? {
if (binding == null) {
binding = FragmentDemoBinding.inflate(inflater, container, false)
}
retainInstance = true
return binding?.root
}
編輯 :實際上,在閱讀更多內容時,我不確定嘗試在導航組件中使用保留的片段是否有意義。 如果我需要在配置更改時保留數據,我猜一個無頭的片段或使用onSaveInstance或ViewModel組件等。
在onDestroyView方法中,刪除所有視圖或僅刪除動畫視圖。
override fun onDestroyView() {
if(view != null){
val parent = view.parent
parent.removeAllViews
}
super.onDestroyView()
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.