1

我已经实现了一个Layout必须向下和向上流动的动画。动画恰恰必须在低和高之间流动。此网格视图位于ExpandbleListView. 因此,当我关闭所有组时,动画非常流畅。当列表上的组是打开的,有很多元素,但是动画被触发时,它并​​不像我希望的那样流畅。我将发布我的动画代码:

    public void expand(final View v) {
    v.measure(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
    final int targtetHeight = v.getMeasuredHeight();

    v.getLayoutParams().height = 0;
    v.setVisibility(View.VISIBLE);
    Animation a = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime,
                Transformation t) {
            v.getLayoutParams().height = interpolatedTime == 1 ? LayoutParams.WRAP_CONTENT
                    : (int) (targtetHeight * interpolatedTime);
            v.requestLayout();
        }

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

    Interpolator i = AnimationUtils.loadInterpolator(this,
            android.R.anim.linear_interpolator);
    a.setInterpolator(i);
    a.setDuration(200);
    v.startAnimation(a);
}

和 :

public static void collapse(final View v) {
    final int initialHeight = v.getMeasuredHeight();
    Animation a = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime,
                Transformation t) {
            if (interpolatedTime == 1) {
                v.setVisibility(View.GONE);
            } else {
                v.getLayoutParams().height = initialHeight
                        - (int) (initialHeight * interpolatedTime);
                v.requestLayout();
            }
        }

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

    // 1dp/ms
    a.setDuration(200);
    v.startAnimation(a);
}

如何使动画更流畅?

--> 编辑:我错了,我更正了

4

0 回答 0