Android动画布局改变了重量高度

时间:2015-04-13 15:16:38

标签: java android android-layout animation layout

我有两个布局

[layout 1]
[layout 2]

同等重量。当我向下滚动时,我会更改[layout 1][layout 2]的权重。

我想知道如何设置布局更改权重的动画。 我试过了

android:animateLayoutChanges="true"

LayoutTransition transition = new LayoutTransition();
mapLayout.setLayoutTransition(transition);`

但这些方法都不起作用。

2 个答案:

答案 0 :(得分:0)

您可以执行类似于此调整大小动画的操作。

public class ResizeAnimation extends Animation
{
    int _startWidth;
    int _targetWidth;
    View _view;
    private int _targetHeight;
    private int _startHeight;

    public ResizeAnimation(View view, int targetWidth, int targetHeight)
    {
        _view = view;
        _targetWidth = targetWidth;
        _startWidth = view.getWidth();

        _targetHeight = targetHeight;
        _startHeight = view.getMeasuredHeight();
        setFillAfter(true);
    }

    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t)
    {
        int newWidth = (int) (_startWidth + (_targetWidth - _startWidth) * interpolatedTime);
        int newHeight = (int) (_startHeight + (_targetHeight - _startHeight) * interpolatedTime);

        _view.getLayoutParams().width = newWidth;
        _view.getLayoutParams().height = newHeight;
        _view.requestLayout();
    }

    @Override
    public boolean willChangeBounds()
    {
        return true;
    }
}

答案 1 :(得分:0)

private class ExpandAnimation extends Animation {

        private float mStartWeight;
        private float mDeltaWeight;
        private LinearLayout mContent;
        private boolean direction;// true - up; false - down

        public ExpandAnimation(LinearLayout content, float startWeight,
                float endWeight) {
            mStartWeight = startWeight;
            mDeltaWeight = endWeight - startWeight;
            mContent = content;
        }

        @Override
        protected void applyTransformation(float interpolatedTime,
                Transformation t) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mContent
                    .getLayoutParams();
            mStartWeight = lp.weight;
            lp.weight = (mStartWeight + (mDeltaWeight * interpolatedTime));
            mContent.setLayoutParams(lp);
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    }