@Override protected float getTopFadingEdgeStrength() { // Disable vertical fading at the top when the pinned header is present return mSize > 0 ? 0 : super.getTopFadingEdgeStrength(); }
@Override public boolean onTouchEvent(MotionEvent ev) { if (mHeaderTouched) { if (ev.getAction() == MotionEvent.ACTION_UP) { mHeaderTouched = false; } return true; } return super.onTouchEvent(ev); };
/** * Brings the specified position to view by optionally performing a jump-scroll maneuver: * first it jumps to some position near the one requested and then does a smooth * scroll to the requested position. This creates an impression of full smooth * scrolling without actually traversing the entire list. If smooth scrolling is * not requested, instantly positions the requested item at a preferred offset. */ public void requestPositionToScreen(int position, boolean smoothScroll) { mRequestedScrollPosition = position; mSmoothScrollRequested = smoothScroll; requestLayout(); }
mRequestedScrollPosition = -1; int firstPosition = getFirstVisiblePosition() + 1; int lastPosition = getLastVisiblePosition(); if (position >= firstPosition && position <= lastPosition) { return; // Already on screen final int offset = (int) (getHeight() * PREFERRED_SELECTION_OFFSET_FROM_TOP); if (!mSmoothScrollRequested) { setSelectionFromTop(position, offset); if (position < firstPosition) { preliminaryPosition = position + twoScreens; if (preliminaryPosition >= getCount()) { preliminaryPosition = getCount() - 1; setSelection(preliminaryPosition); super.layoutChildren(); setSelection(preliminaryPosition); super.layoutChildren(); smoothScrollToPositionFromTop(position, offset);
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); mHeaderPaddingStart = getPaddingStart(); mHeaderWidth = r - l - mHeaderPaddingStart - getPaddingEnd(); }
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { mHeaderTouched = false; if (super.onInterceptTouchEvent(ev)) { return true; } if (mScrollState == SCROLL_STATE_IDLE) { final int y = (int)ev.getY(); final int x = (int)ev.getX(); for (int i = mSize; --i >= 0;) { PinnedHeader header = mHeaders[i]; // For RTL layouts, this also takes into account that the scrollbar is on the left // side. final int padding = getPaddingLeft(); if (header.visible && header.y <= y && header.y + header.height > y && x >= padding && padding + header.view.getWidth() >= x) { mHeaderTouched = true; if (mScrollToSectionOnHeaderTouch && ev.getAction() == MotionEvent.ACTION_DOWN) { return smoothScrollToPartition(i); } else { return true; } } } } return false; }
super.dispatchDraw(canvas);