Java android中三窗格视图动画的推荐方法?

Java android中三窗格视图动画的推荐方法?,java,android,animation,Java,Android,Animation,我一直在用Android玩一些动画,和往常一样,这是一团混乱。首先,守则: public class ResizeWidthAnimation extends Animation { private float mStartWeight; private float mWeight; private float mStartWeight2; private float mWeight2; private int mCurrentWidth; pri

我一直在用Android玩一些动画,和往常一样,这是一团混乱。首先,守则:

public class ResizeWidthAnimation extends Animation {
    private float mStartWeight;
    private float mWeight;
    private float mStartWeight2;
    private float mWeight2;
    private int mCurrentWidth;
    private int mCurrentWidth2;
    private View mView;
    private int mFinalWidth2;
    private View mSecondFrame;

    public ResizeWidthAnimation(View view, View secondFrame, float weight, int finalWidth2) {
        mView = view;
        mSecondFrame = secondFrame;
        mFinalWidth2 = finalWidth2;

        mWeight = weight;
        mStartWeight = ((LinearLayout.LayoutParams)view.getLayoutParams()).weight;
        mWeight2 = weight;
        mStartWeight2 = ((LinearLayout.LayoutParams)secondFrame.getLayoutParams()).weight;

        mCurrentWidth = view.getMeasuredWidth();
        mCurrentWidth2 = secondFrame.getMeasuredWidth();
    }

    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
        LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mView.getLayoutParams();
        lp.weight = (float) (mStartWeight + ((mWeight - mStartWeight) * interpolatedTime));
        mView.requestLayout();
        mCurrentWidth = mView.getMeasuredWidth();

        if (mCurrentWidth2 >= mFinalWidth2) {
            return;
        }
        LinearLayout.LayoutParams lp2 = (LinearLayout.LayoutParams) mSecondFrame.getLayoutParams();
        lp2.weight = (float) (mStartWeight2 + ((mWeight2 - mStartWeight2) * interpolatedTime));
        mSecondFrame.requestLayout();
        mCurrentWidth2 = mSecondFrame.getMeasuredWidth();

    }

    @Override
    public void initialize(int width, int height, int parentWidth, int parentHeight) {
        super.initialize(width, height, parentWidth, parentHeight);
    }

    @Override
    public boolean willChangeBounds() {
        return true;
    }
}
这是一个基于两个布局权重的动画(并排放置。一个初始权重为0f,另一个为8f,第三个为2f。这应该做的是:

  • 假设提供的位置为weightsum=10f,布局按如下方式线性放置 第一|第二|第三
  • 将左侧布局从8f权重设置为5f
  • 同时做两件事:

    a) 将第二个布局(放置在右侧)从0f设置为“大约”5f

    b) 将第三个布局向右滑动,当到达a)的末端时,检查是否有足够的位置绘制第三个布局的32dp宽部分,该部分向右滑动。如果是这样,请停止动画并有效地为第三个布局留出一些位置

  • 我知道requestLayout()调用很昂贵,而且上述解决方案并不完美,所以我想知道是否有人能提供更好的解决方案。最糟糕的是,我需要与api v8兼容