fragments, android:zAdjustment (z order) and animations

前端 未结 3 1552
小蘑菇
小蘑菇 2021-02-04 00:17

I\'m using the support library. Now, I want to have a fragment shifting in from the bottom, moving OVER the previous one.

For this I use this to keep the previous fragme

3条回答
  •  说谎
    说谎 (楼主)
    2021-02-04 00:30

    You can override the onCreateAnimation method and for any animations you can check what animation is currently running and if you need it to be on top, set the Z-axis from there.

    override fun onCreateAnimation(transit: Int, enter: Boolean, nextAnim: Int): Animation? {
        if (nextAnim == R.anim.enter_from_right || nextAnim == R.anim.exit_to_right) {
            ViewCompat.setTranslationZ(view, 1f)
        } else {
            ViewCompat.setTranslationZ(view, 0f)
        }
    
        return super.onCreateAnimation(transit, enter, nextAnim)
    }
    

    Recommend implementing this as a base Fragment class for all your fragments.

提交回复
热议问题