List of usage examples for android.widget AdapterView getLastVisiblePosition
public int getLastVisiblePosition()
From source file:com.recyclerviewpulldownrefresh.view.refresh.AbPullToRefreshView.java
/** * ??/* w w w . j av a2 s.c om*/ * * @return */ public boolean canChildScrollDown() { if (!mEnableLoadMore) { return false; } if (mTarget instanceof AdapterView<?>) { AdapterView<?> absListView = (AdapterView<?>) mTarget; View lastChild = absListView.getChildAt(absListView.getChildCount() - 1); if (lastChild == null) { return true; } // ??viewBottom?ViewmAdapterView?view, // ViewmAdapterView?? if (lastChild.getBottom() <= getHeight() && absListView.getLastVisiblePosition() == absListView.getCount() - 1) { return true; } } else if (mTarget instanceof WebView) { WebView webview = (WebView) mTarget; return webview.getContentHeight() * webview.getScale() <= webview.getHeight() + webview.getScrollY(); } else if (mTarget instanceof ScrollView) { ScrollView scrollView = (ScrollView) mTarget; View childView = scrollView.getChildAt(0); if (childView != null) { return childView.getMeasuredHeight() <= getHeight() + mScrollView.getScrollY(); } } else if (mTarget instanceof RecyclerView) { int lastVisiblePosition = 0; View childView = null; RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager(); if (layoutManager instanceof LinearLayoutManager) { lastVisiblePosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition(); childView = layoutManager.findViewByPosition(lastVisiblePosition); } else if (layoutManager instanceof GridLayoutManager) { lastVisiblePosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition(); childView = layoutManager.findViewByPosition(lastVisiblePosition); } else if (layoutManager instanceof StaggeredGridLayoutManager) { int[] spanPosition = new int[((StaggeredGridLayoutManager) layoutManager).getSpanCount()]; ((StaggeredGridLayoutManager) layoutManager).findLastVisibleItemPositions(spanPosition); lastVisiblePosition = getLastVisibleItemPosition(spanPosition); childView = getLastVisibleItemBottomView(layoutManager, spanPosition, lastVisiblePosition); } if (null == childView) { return false; } if (lastVisiblePosition == layoutManager.getItemCount() - 1 && childView.getBottom() + layoutManager.getBottomDecorationHeight(childView) <= mTarget.getBottom()) { return true; } } else { return ViewCompat.canScrollVertically(mTarget, 1); } return false; }