Пример #1
0
 private void updateHeaderHeight(float delta) {
   mHeaderView.setVisiableHeight((int) delta + mHeaderView.getVisiableHeight());
   if (mEnablePullRefresh && !mPullRefreshing) { // 未处于刷新状态,更新箭头
     if (mHeaderView.getVisiableHeight() > mHeaderViewHeight) {
       mHeaderView.setState(ViewXListHeader.STATE_READY);
     } else {
       mHeaderView.setState(ViewXListHeader.STATE_NORMAL);
     }
   }
   setSelection(0); // scroll to top each time
 }
Пример #2
0
  @Override
  public boolean onTouchEvent(MotionEvent ev) {
    if (mLastY == -1) {
      mLastY = ev.getRawY();
    }

    switch (ev.getAction()) {
      case MotionEvent.ACTION_DOWN:
        mLastY = ev.getRawY();
        break;
      case MotionEvent.ACTION_MOVE:
        final float deltaY = ev.getRawY() - mLastY;
        mLastY = ev.getRawY();
        if (getFirstVisiblePosition() == 0 && (mHeaderView.getVisiableHeight() > 0 || deltaY > 0)) {
          // the first item is showing, header has shown or pull down.
          updateHeaderHeight(deltaY / OFFSET_RADIO);
          invokeOnScrolling();
        } else if (getLastVisiblePosition() == mTotalItemCount - 1
            && (mFooterView.getBottomMargin() > 0 || deltaY < 0)) {
          // last item, already pulled up or want to pull up.
          updateFooterHeight(-deltaY / OFFSET_RADIO);
        }
        break;
      default:
        mLastY = -1; // reset
        if (getFirstVisiblePosition() == 0) {
          // invoke refresh
          if (mEnablePullRefresh && mHeaderView.getVisiableHeight() > mHeaderViewHeight) {
            mPullRefreshing = true;
            mHeaderView.setState(ViewXListHeader.STATE_REFRESHING);
            if (mListViewListener != null) {
              mListViewListener.onRefresh();
            }
          }
          resetHeaderHeight();
        } else if (getLastVisiblePosition() == mTotalItemCount - 1) {
          // invoke load more.
          if (mEnablePullLoad
              && mFooterView.getBottomMargin() > PULL_LOAD_MORE_DELTA
              && !mPullLoading) {
            startLoadMore();
          }
          resetFooterHeight();
        }
        break;
    }
    return super.onTouchEvent(ev);
  }
Пример #3
0
 /** reset header view's height. */
 private void resetHeaderHeight() {
   int height = mHeaderView.getVisiableHeight();
   if (height == 0) // not visible.
   return;
   // refreshing and header isn't shown fully. do nothing.
   if (mPullRefreshing && height <= mHeaderViewHeight) {
     return;
   }
   int finalHeight = 0; // default: scroll back to dismiss header.
   // is refreshing, just scroll back to show all the header.
   if (mPullRefreshing && height > mHeaderViewHeight) {
     finalHeight = mHeaderViewHeight;
   }
   mScrollBack = SCROLLBACK_HEADER;
   mScroller.startScroll(0, height, 0, finalHeight - height, SCROLL_DURATION);
   // trigger computeScroll
   invalidate();
 }