Flynn
Flynn

Reputation: 6181

Android: Translate Animation and Relative Layout

I want to reveal a View by moving everything below where it is going to apear, and then make it visible (giving the effect that the items below it just slid to made room for it). I am currently using a TranslateAnimation on a View in a RelativeLayout. My first thought was to measure the View that I am about to make visible, and translate the first View effected. My hope was that if I animated one View, that it would also move everything else that was dependent on it in the layout. After trying though, only the view with the animation moves. I know I could just place everything below in a layout, and translate the layout, but for the sake of layout efficiency and making a process as generic as possible,

How can I make all of the View's RealtiveLayout dependents move with it, or otherwise get the effect described?

Upvotes: 2

Views: 4530

Answers (2)

Vinay W
Vinay W

Reputation: 10190

write an animation class

public class Animate extends Animation implements AnimationListener {
    public int height,width;

    @Override
    public void initialize(int width, int height, int parentWidth,
            int parentHeight) {
        // TODO Auto-generated method stub
        super.initialize(width, height, parentWidth, parentHeight);
        this.width = width;
        this.height = height;
        setDuration(500);
        setFillAfter(true);
        setInterpolator(new LinearInterpolator());
    }

    Camera camera = new Camera();

    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
        // TODO Auto-generated method stub
        super.applyTransformation(interpolatedTime, t);

        Matrix matrix = t.getMatrix();
        camera.save();

        camera.getMatrix(matrix);
        matrix.setTranslate(0, (-height * interpolatedTime));

        matrix.preTranslate(0, -height);
        camera.restore();

    }

use it to animate your layout

View v= new View(); 
// use whatever view you want and set it up
v.startAnimation(new Animate());

Upvotes: 0

Bondax
Bondax

Reputation: 3163

Apply the animation to the whole RelativeLayout or a subgroup that is encapsulated in a grouping RelativeLayout within the top RelativeLayout.

Upvotes: 1

Related Questions