片段过渡时的动画高度不起作用

时间:2018-10-25 07:19:36

标签: android android-fragments android-animation android-transitions

我正在创建一个自定义动画,该动画将片段从回收站视图上轻按的项目位置滑入和滑出。它还会动画化片段的高度。 因此,发生了三种动画 1.翻译Y 2.身高 3.淡入淡出 打开片段时一切正常,但仅关闭片段高度并没有改变

class SlideFromPoint(val epicCenterRect: Rect) : Slide() {

    override fun onAppear(sceneRoot: ViewGroup?, view: View?, startValues: TransitionValues?, endValues: TransitionValues?): Animator {
        val translateAnimation = ObjectAnimator.ofFloat(view, "translationY",epicCenterRect.top.toFloat(),0f)
        val fadeInAnimator = ObjectAnimator.ofFloat(view, View.ALPHA, 0f, 1f)
        val heightAnimation = ValueAnimator.ofInt(epicCenterRect.height(),view!!.measuredHeight)
        heightAnimation.addUpdateListener { value ->
            val animatedValue = value.animatedValue as Int
            view.layoutParams.height = animatedValue
            view.requestLayout()
        }
        return animatorSet(translateAnimation,heightAnimation,fadeInAnimator)
    }

    override fun onDisappear(sceneRoot: ViewGroup?, view: View?, startValues: TransitionValues?, endValues: TransitionValues?): Animator {
        val translateAnimation = ObjectAnimator.ofFloat(view, "translationY",0f,epicCenterRect.top.toFloat())
        val fadeInAnimator = ObjectAnimator.ofFloat(view, View.ALPHA, 1f, 0f)
        val heightAnimation = ValueAnimator.ofInt(view!!.measuredHeight,epicCenterRect.height())
        heightAnimation.addUpdateListener { value ->
            val animatedValue = value.animatedValue as Int
            view.layoutParams.height = animatedValue
            view.requestLayout()
        }
        return animatorSet(translateAnimation,heightAnimation,fadeInAnimator)
    }

    private fun animatorSet(translateAnimation: Animator, heightAnimation: Animator, fadeInAnimator: ObjectAnimator): AnimatorSet {
        val animatorSet = AnimatorSet()
        animatorSet.playTogether(listOf(translateAnimation,heightAnimation,fadeInAnimator))
        return animatorSet
    }

}

,但是在onDisappear中的值动画制作器中,将动画值设置为layoutparams。 仍然没有改变。 有什么想法吗?

0 个答案:

没有答案