I have two fragments (A, B), among which I can swap; what I wanted to achieve was a slide up / down animation between them every time I swapped them.
I tried using two object animator like this:
//slide up
<objectAnimator
android:interpolator="@android:interpolator/linear"
android:propertyName="translationY"
android:valueType="intType"
android:valueFrom="1920"
android:valueTo="0"
android:duration="1000" />
//Slide down
<objectAnimator
android:interpolator="@android:interpolator/linear"
android:propertyName="translationY"
android:valueType="intType"
android:valueFrom="0"
android:valueTo="1920"
android:duration="1000" />
but it didn't work because the two fragment were overlapping. So how can I do that animation?
Fragment A:
class FragmentA : Fragment(){
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
buttonA.setOnClickListener {
activity.supportFragmentManager.beginTransaction()
.setCustomAnimations(R.animator.slide_dowm, R.animator.slide_up)
.replace(R.id.container, FragmentB()).commit()
}
}
}
Fragment B:
class FragmentB : Fragment(){
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
buttonB.setOnClickListener {
activity.supportFragmentManager.beginTransaction()
.setCustomAnimations(R.animator.slide_up, R.animator.slide_down)
.replace(R.id.container, FragmentB()).commit()
}
}
}