我正在尝试向我的片段添加一个共享元素转换,这将在顶部创建一个居中徽标之类的东西。我通过共享元素转换成功地做到了这一点,但徽标也应用了一些窗口插图。问题在于只有在共享元素转换完成后才会应用窗口插图。这使得视图看起来像跳转到它们的最终位置。
我正在使用下面的代码。
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)
}
有人可以帮我吗?
如何在执行共享元素转换之前先应用窗口插图,以免发生“跳跃”?