动画layout_weight更改

时间:2015-04-17 13:16:54

标签: android animation objectanimator

是否可以为视图的layout_weight更改设置动画?

我试过了:

  

ObjectAnimator anim = ObjectAnimator.ofFloat(headerRoot,   " layout_weight",ws,1f);           anim.setDuration(1500);           anim.addUpdateListener(本);           anim.start();

这对我的布局没有影响。 objectAnimator是否能够操纵视图的layout_weight属性?

2 个答案:

答案 0 :(得分:0)

只需使用此处提供的课程:https://stackoverflow.com/a/20334557/1763138

private class ExpandAnimation extends Animation {

    private final float mStartWeight;
    private final float mDeltaWeight;

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

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

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

并将mContent更改为headerRoot

答案 1 :(得分:0)

  

这对我的布局没有影响。 objectAnimator是否能够操纵视图的layout_weight属性?

不,不是。 ObjectAnimator使用对象的setter方法更新其值。 LayoutParam没有setWeight方法,只有weight属性可以更改。

这一切都在这里解释:http://developer.android.com/guide/topics/graphics/prop-animation.html#object-animator