I have two fragment (A, B), among wich 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 worked 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()
}
}
}