从右到左调整动画大小

时间:2016-12-07 18:28:15

标签: java android android-animation

我想用动画从右到左调整视图大小,从X到0,现在我已经创建了这个类:

public class ResizeAnimationRightToLeft extends Animation {

    private View mView;
    private float mToHeight;
    private float mFromHeight;

    private float mToWidth;
    private float mFromWidth;

    public ResizeAnimationRightToLeft(View v, float fromWidth, float fromHeight, float toWidth, float toHeight) {
        mToHeight = toHeight;
        mToWidth = toWidth;
        mFromHeight = fromHeight;
        mFromWidth = fromWidth;
        mView = v;
    }

    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
        float height =
                (mToHeight - mFromHeight) * interpolatedTime + mFromHeight;
        float width = (mToWidth - mFromWidth) * interpolatedTime + mFromWidth;
        ViewGroup.LayoutParams p = mView.getLayoutParams();
        p.height = (int) height;
        p.width = (int) width;
        mView.requestLayout();
    }
}

比我使用:

ResizeAnimationRightToLeft scale = 
    new ResizeAnimationRightToLeft(layout, 0, DIM_HEIGHT, DIM_WIDTH, DIM_HEIGHT);

但是从左到右调整大小视图,现在我不明白如何扭转这种情况,有人可以指示我吗?

感谢。

1 个答案:

答案 0 :(得分:0)

我已经解决了这个问题:

ScaleAnimation animationRightToLeft = new ScaleAnimation(0.0f, 1.0f, 1.0f, 1.0f, Animation.RELATIVE_TO_SELF,1.0f, Animation.RELATIVE_TO_SELF, 0.5f);
animationRightToLeft.setDuration(200);

ScaleAnimation animationLeftToRight = new ScaleAnimation(0.0f, 1.0f, 1.0f, 1.0f, Animation.RELATIVE_TO_SELF,0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
animationLeftToRight.setDuration(200);