Android-MaterialRefreshLayout icon indicating copy to clipboard operation
Android-MaterialRefreshLayout copied to clipboard

MaterialRefreshLayout跑在4.2.2的机子上卡顿

Open bitian123 opened this issue 9 years ago • 2 comments

MaterialRefreshLayout跑在4.2.2的机子上时,如果只下拉一点,界面会卡顿,不会复原到原来的样子,不知道作者有没有遇到过。

bitian123 avatar Nov 29 '16 06:11 bitian123

查了一下源代码, 发现MaterialRefreshLayout类中有个方法, 其中一个关键性的回调没触发导致的

public void createAnimatorTranslationY(final View v, final float h, final FrameLayout fl) {
        ViewPropertyAnimatorCompat viewPropertyAnimatorCompat = ViewCompat.animate(v);
        viewPropertyAnimatorCompat.setDuration(250);
        viewPropertyAnimatorCompat.setInterpolator(new DecelerateInterpolator());
        viewPropertyAnimatorCompat.translationY(h);
        viewPropertyAnimatorCompat.start();
        viewPropertyAnimatorCompat.setUpdateListener(new ViewPropertyAnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(View view) {
                float height = ViewCompat.getTranslationY(v);
                fl.getLayoutParams().height = (int) height;
                fl.requestLayout();
            }
        });
    }

其中setUpdateListener函数在API < 19的时候不工作, 可以查看android的源码发现:

/**
     * Sets a listener for update events in the underlying Animator that runs
     * the property animations.
     *
     * <p>Prior to API 19, this method will do nothing.</p>
     *
     * @param listener The listener to be called with update events. A value of
     * <code>null</code> removes any existing listener.
     * @return This object, allowing calls to methods in this class to be chained.
     */
    public ViewPropertyAnimatorCompat setUpdateListener(
            final ViewPropertyAnimatorUpdateListener listener) {
        final View view;
        if ((view = mView.get()) != null) {
            if (Build.VERSION.SDK_INT >= 19) {
                ValueAnimator.AnimatorUpdateListener wrapped = null;
                if (listener != null) {
                    wrapped = new ValueAnimator.AnimatorUpdateListener() {
                        @Override
                        public void onAnimationUpdate(ValueAnimator valueAnimator) {
                            listener.onAnimationUpdate(view);
                        }
                    };
                }
                view.animate().setUpdateListener(wrapped);
            }
        }
        return this;
    }

caojianhua avatar Aug 16 '18 10:08 caojianhua

尝试修改如下, 发现可以避免该问题

public void createAnimatorTranslationY(final View v, final float h, final FrameLayout fl) {
        if (Build.VERSION.SDK_INT >= 19) {
            ViewPropertyAnimatorCompat viewPropertyAnimatorCompat = ViewCompat.animate(v);
            viewPropertyAnimatorCompat.setDuration(250);
            viewPropertyAnimatorCompat.setInterpolator(new DecelerateInterpolator());
            viewPropertyAnimatorCompat.translationY(h);
            viewPropertyAnimatorCompat.start();
            viewPropertyAnimatorCompat.setUpdateListener(new ViewPropertyAnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(View view) {
                    float height = ViewCompat.getTranslationY(v);
                    fl.getLayoutParams().height = (int) height;
                    fl.requestLayout();
                }
            });
        } else {
            ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(v, View.TRANSLATION_Y, h)
                    .setDuration(250);
            objectAnimator.setInterpolator(new DecelerateInterpolator());
            objectAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    float height = ViewCompat.getTranslationY(v);
                    fl.getLayoutParams().height = (int) height;
                    fl.requestLayout();
                }
            });
            objectAnimator.start();
        }

    }

caojianhua avatar Aug 16 '18 11:08 caojianhua