Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animating a group of children in a viewgroup

I'm working on a custom ViewGroup.

This ViewGroup has a bunch of children. I need to animate a few and change their position. I understand that Android animations move just the bitmap and not the real object. I've been trying to MOVE them by following various resources but have failed.

What I'm doing with ViewGroup so far:

  1. Measure children and the ViewGroup
  2. Position children in onLayout

What I'm trying to do further

Use a custom animation to move a small subset of the children. I'm using a custom Animation object because I need to move a bunch of Views and I'm applying translationX on all of them together. The other option that I know is to start a separate Animation on all of them and the thought of which makes me think it's gonna be unoptimized.

Problem

Views animate fine, but their real position remains unchanged. So the next time I'm trying to do the same kind of animation, but on the new co-ordinates, it doesn't work. Because, their positions haven't updated.

What did I try

  1. Use onAnimationEnd to layout each of the children to the new left, top, right and bottom position. All views vanished
  2. On onAnimationEnd, reset translationX to zero and then start re-positioning the views. No effect of calling view.setTranslationX(0f)

Can someone please help me with the correct way of doing this? Thanks

like image 200
kishu27 Avatar asked Nov 11 '22 12:11

kishu27


1 Answers

when animating call layout() on your child Views

like image 143
pskink Avatar answered Nov 14 '22 22:11

pskink