diff --git a/qmui/src/main/java/com/qmuiteam/qmui/widget/QMUICollapsingTopBarLayout.java b/qmui/src/main/java/com/qmuiteam/qmui/widget/QMUICollapsingTopBarLayout.java index df9458cb0..2053a804e 100644 --- a/qmui/src/main/java/com/qmuiteam/qmui/widget/QMUICollapsingTopBarLayout.java +++ b/qmui/src/main/java/com/qmuiteam/qmui/widget/QMUICollapsingTopBarLayout.java @@ -95,6 +95,7 @@ public class QMUICollapsingTopBarLayout extends FrameLayout { private int mScrimVisibleHeightTrigger = -1; private AppBarLayout.OnOffsetChangedListener mOnOffsetChangedListener; + private ValueAnimator.AnimatorUpdateListener mScrimUpdateListener; int mCurrentOffset; @@ -509,6 +510,26 @@ public void setScrimsShown(boolean shown, boolean animate) { } } + /** + * + * @param scrimUpdateListener 为 null 则是 removeUpdateListener + */ + public void setScrimUpdateListener(ValueAnimator.AnimatorUpdateListener scrimUpdateListener) { + if (mScrimUpdateListener != scrimUpdateListener) { + if (mScrimAnimator == null) { + mScrimUpdateListener = scrimUpdateListener; + } else { + if (mScrimUpdateListener != null) { + mScrimAnimator.removeUpdateListener(mScrimUpdateListener); + } + mScrimUpdateListener = scrimUpdateListener; + if(mScrimUpdateListener != null){ + mScrimAnimator.addUpdateListener(mScrimUpdateListener); + } + } + } + } + private void animateScrim(int targetAlpha) { ensureToolbar(); if (mScrimAnimator == null) { @@ -524,6 +545,9 @@ public void onAnimationUpdate(ValueAnimator animator) { setScrimAlpha((Integer) animator.getAnimatedValue()); } }); + if (mScrimUpdateListener != null) { + mScrimAnimator.addUpdateListener(mScrimUpdateListener); + } } else if (mScrimAnimator.isRunning()) { mScrimAnimator.cancel(); } diff --git a/qmuidemo/src/main/java/com/qmuiteam/qmuidemo/fragment/components/QDCollapsingTopBarLayoutFragment.java b/qmuidemo/src/main/java/com/qmuiteam/qmuidemo/fragment/components/QDCollapsingTopBarLayoutFragment.java index 30f6be0e2..71fc85878 100644 --- a/qmuidemo/src/main/java/com/qmuiteam/qmuidemo/fragment/components/QDCollapsingTopBarLayoutFragment.java +++ b/qmuidemo/src/main/java/com/qmuiteam/qmuidemo/fragment/components/QDCollapsingTopBarLayoutFragment.java @@ -1,7 +1,9 @@ package com.qmuiteam.qmuidemo.fragment.components; +import android.animation.ValueAnimator; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -23,6 +25,7 @@ @Widget(widgetClass = QMUICollapsingTopBarLayout.class, iconRes = R.mipmap.icon_grid_collapse_top_bar) public class QDCollapsingTopBarLayoutFragment extends BaseFragment { + private static final String TAG = "CollapsingTopBarLayout"; private View mRootView; QDRecyclerViewAdapter mRecyclerViewAdapter; @@ -44,6 +47,13 @@ protected View onCreateView() { mRecyclerViewAdapter.setItemCount(10); mRecyclerView.setAdapter(mRecyclerViewAdapter); + mCollapsingTopBarLayout.setScrimUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + @Override + public void onAnimationUpdate(ValueAnimator animation) { + Log.i(TAG, "scrim: " + animation.getAnimatedValue()); + } + }); + return mRootView; }