import android.widget.ListView; //导入方法依赖的package包/类
@Override
public AnimatorUpdateListener onLoadingFinish(final RefreshKernel kernel, final int footerHeight, int startDelay, final int duration) {
if (mScrollableView != null && kernel.getRefreshLayout().isEnableScrollContentWhenLoaded()) {
if (!canScrollDown(mScrollableView)) {
return null;
}
if (mScrollableView instanceof AbsListView && !(mScrollableView instanceof ListView) && Build.VERSION.SDK_INT < 19) {
if (startDelay > 0) {
kernel.getRefreshLayout().getLayout().postDelayed(new Runnable() {
@Override
public void run() {
((AbsListView) mScrollableView).smoothScrollBy(footerHeight, duration);
}
}, startDelay);
} else {
((AbsListView) mScrollableView).smoothScrollBy(footerHeight, duration);
}
return null;
}
return new AnimatorUpdateListener() {
int lastValue = kernel.getSpinner();
@Override
public void onAnimationUpdate(ValueAnimator animation) {
int value = (int) animation.getAnimatedValue();
try {
if (mScrollableView instanceof ListView) {
if (Build.VERSION.SDK_INT >= 19) {
((ListView) RefreshContentWrapper.this.mScrollableView).scrollListBy(value - lastValue);
} else {
// ListViewCompat.scrollListBy((ListView) mScrollableView, value - lastValue);
ListView listView = (ListView) RefreshContentWrapper.this.mScrollableView;
final int firstPosition = listView.getFirstVisiblePosition();
if (firstPosition == ListView.INVALID_POSITION) {
return;
}
final View firstView = listView.getChildAt(0);
if (firstView == null) {
return;
}
final int newTop = firstView.getTop() - (value - lastValue);
listView.setSelectionFromTop(firstPosition, newTop);
}
} else {
mScrollableView.scrollBy(0, value - lastValue);
}
} catch (Throwable ignored) {
//根据用户反馈,此处可能会有BUG
}
lastValue = value;
}
};
}
return null;
}