@Override public void onHeaderScroll( AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount, int index) { Log.i(TAG, "onHeaderScroll -> firstVisibleItem: " + firstVisibleItem); if (mTabView == null || mIndex != index || mHeaderView == null) { return; } if (restoreListView((ListView) view)) { return; } if (firstVisibleItem != 0) { startAnimation(-mMaxScrollHeight); return; } final View topView = view.getChildAt(firstVisibleItem); if (topView == null) { startAnimation(0); return; } int y = topView.getTop() > 0 ? 0 : topView.getTop(); Log.i(TAG, "onHeaderScroll -> topView y: " + y); Log.i(TAG, "onHeaderScroll -> topView height: " + topView.getHeight()); Log.i(TAG, "onHeaderScroll -> mHeaderView height: " + mHeaderView.getHeight()); int moveToY = Math.max(y, -mMaxScrollHeight); startAnimation(moveToY); if (mHeaderView != null) { Log.i(TAG, "onHeaderScroll -> header height: " + mHeaderView.getVisiableHeight()); } }
/** * headerView滑动动画,支持1.6+版本 HONEYCOMB以上版本使用动画滑动,HONEYCOMB一下版本更改padding实现 * * @param value */ public void startAnimation(int value) { if (mHeaderView == null) { return; } mScrollY[mIndex] = value; if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { Interpolator interpolator = AnimationUtils.loadInterpolator( mContext, android.R.anim.accelerate_decelerate_interpolator); ObjectAnimator animator = ObjectAnimator.ofFloat(mHeaderView, "y", value); animator.setInterpolator(interpolator); animator.setDuration(0); animator.start(); } else { mHeaderView.setPadding(0, value, 0, 0); } }
@Override public void onHeaderPull(int height) { if (mHeaderView != null) { mHeaderView.setVisiableHeight(height); } }
@Override public void setState(int state) { if (mHeaderView != null) { mHeaderView.setState(state); } }