2

我想通过将所有内容移动到它要出现的位置来显示一个视图,然后使其可见(给出它下面的项目只是滑动为它腾出空间的效果)。我目前TranslateAnimation在 a 中的视图上使用 a RelativeLayout。我的第一个想法是测量我将要显示的视图,并翻译第一个受影响的视图。我的希望是,如果我为一个 View 设置动画,它也会移动布局中依赖于它的所有其他内容。但尝试后,只有带有动画的视图移动。我知道我可以把下面的所有东西都放在一个布局中,然后翻译布局,但是为了布局效率和使流程尽可能通用,

如何使 View 的所有 RealtiveLayout 依赖项随其移动,或者以其他方式获得所描述的效果?

4

2 回答 2

1

将动画应用于整个RelativeLayout 或封装在顶部RelativeLayout 内的分组RelativeLayout 中的子组。

于 2012-07-17T06:59:14.623 回答
0

写一个动画类

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();

    }

用它来动画你的布局

View v= new View(); 
// use whatever view you want and set it up
v.startAnimation(new Animate());
于 2012-07-17T07:30:30.747 回答