【发布时间】:2023-02-08 04:01:10
【问题描述】:
在使用视图寻呼机替换片段中的过渡时,我遇到了崩溃。在布局中,我的片段内部有一个 constraintLayout 和 viewPager2。我已经尝试在 constraintLayout 中添加 android:transitionGroup="true" 但未成功:(
访问包含视图寻呼机的片段时出现以下错误:
java.lang.IllegalStateException: ViewPager2 不支持直接子视图
我对替换片段的扩展是这样的:
fun AppCompatActivity.replaceTest(fragment: Fragment, frameId: Int, addToBackStack: Boolean = false) {
supportFragmentManager.beginTransaction().apply {
fragment.enterTransition = Slide(Gravity.END).apply { duration = 300 }
fragment.exitTransition = Slide(Gravity.END).apply { duration = 300 }
setPrimaryNavigationFragment(fragment)
if (addToBackStack) {
addToBackStack(fragment.javaClass.simpleName)
}
replace(frameId, fragment, fragment.javaClass.simpleName)
commitAllowingStateLoss()
}
}
我称之为:
activity.replaceFragmentWithAnimation(SplashScreenFragment.newInstance(payloadType), android.R.id.content, false)
我的包含 viewpager2 的 xml 是:
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/imageSliderViewGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent"
android:transitionGroup="true">
<component.customview.SliderView
android:id="@+id/imageSliderView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:isSlideShow="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
在我的自定义视图“SliderView”中,我也在 constraintLayout 中添加了android:transitionGroup="true"
【问题讨论】:
标签: java android kotlin animation android-viewpager2