1

I am trying to create a screen, on some operation it is required to slide a layout from bottom to the height to match it's length, with a translation animation kind of slide.

Have a look at the screen example:

Initial screen layout view 5 slides in from bottom

As you can see the initial screen layout, the new view 5 slides in from bottom, pushing the entire layout upwards with an animation.

I have tried this: https://stackoverflow.com/a/19766034/1085742

Using the above link, the new view is visible with animation but screen is not sliding down to show the new view 5.

Any idea how to do this!! Thanks in advance.

Community
  • 1
  • 1
AndroidDev
  • 2,627
  • 6
  • 29
  • 41

1 Answers1

0

I also tested this. Apparently an animation with translateY or Y does not change the layout bounds. In other words, the other views do not move up. Neither when using an Animation nor an Animator.

One solution is to animate the margins, if the animated view is in a layout that supports margins. In Kotlin:

val collapse = ValueAnimator.ofInt(0, -someLayoutAndViews1.height)
collapse.addUpdateListener {
    val params = someLayoutAndViews1.layoutParams as ViewGroup.MarginLayoutParams
    params.topMargin = it.animatedValue as Int
    someLayoutAndViews1.layoutParams = params
}
collapse.start()