我试图在我的片段中添加一个共享元素转换,这样可以在顶部创建一个居中的徽标。我通过共享元素转换成功地做到了这一点,但徽标也应用了一些窗口插入。问题在于,只有在共享元素转换完成后,才会应用窗口插入。这使得视图看起来像是跳转到了它们的最终位置。
我正在使用下面的代码。
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = layoutInflater?.inflate(R.layout.onboarding_layout, container, false)
return view
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
ViewCompat.setOnApplyWindowInsetsListener(appimageviewLogo) { view, insets ->
val params = view.layoutParams as ViewGroup.MarginLayoutParams
params.topMargin = params.topMargin + insets.systemWindowInsetTop
insets
}
ViewCompat.setOnApplyWindowInsetsListener(appbuttonSkip) { view, insets ->
val params = view.layoutParams as ViewGroup.MarginLayoutParams
params.bottomMargin = params.bottomMargin + insets.systemWindowInsetBottom
insets.consumeSystemWindowInsets()
}
ViewCompat.requestApplyInsets(appimageviewLogo)
ViewCompat.requestApplyInsets(appbuttonSkip)
}
有人能帮我吗?
在执行共享元素转换之前,如何首先应用窗口插入,以避免发生“跳跃”?