调整动画大小会滞后

时间:2018-09-02 07:29:54

标签: android performance android-animation

我正在开发一个应用程序,并编写了代码以调整视图的大小,如下所示

package com.lynx.zaindelivery.animations;

import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Transformation;

/**
 * Created by moh.rababah on 5/5/2016.
 */
public class ResizeAnimation extends Animation {
    final int startWidth;
    final int targetHight;
    View view;

    public ResizeAnimation(View view, int targetHight) {
        this.view = view;
        this.targetHight = targetHight;
        startWidth = view.getHeight();
    }

    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
        int newHight = (int) (startWidth + (targetHight - startWidth) * interpolatedTime);
        view.getLayoutParams().height = newHight;
            view.requestLayout();
    }

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

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

它可以正常工作,但是比较滞后(targetHight高时)。有什么方法可以提高性能?

0 个答案:

没有答案