Java Code Examples for android.widget.AbsListView#getLastVisiblePosition()
The following examples show how to use
android.widget.AbsListView#getLastVisiblePosition() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ViewScrollChecker.java From Android-Pull-To-Refresh with Apache License 2.0 | 6 votes |
private static boolean performAbsListView(AbsListView view, int direction) { int childCount = view.getChildCount(); if (childCount > 0) { switch (direction) { case DIRECTION_DOWN: ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); int firstItemTop = view.getChildAt(0).getTop(); int listViewTop = view.getTop() + view.getPaddingTop() - lp.topMargin; if (DEBUG_SCROLL_CHECK) L.e(TAG, "firstItemTop=%s,listViewTop=%s", firstItemTop, listViewTop); return (view.getFirstVisiblePosition() > 0 || firstItemTop < listViewTop); case DIRECTION_UP: int lastItemBottom = view.getChildAt(childCount - 1).getBottom(); int listViewBottom = view.getBottom() - view.getPaddingBottom(); if (DEBUG_SCROLL_CHECK) L.e(TAG, "lastItemBottom=%s,listViewBottom=%s", lastItemBottom, listViewBottom); return (view.getLastVisiblePosition() < childCount - 1 || lastItemBottom > listViewBottom); } } if (DEBUG_SCROLL_CHECK) L.e(TAG, "AbsListView cannot scroll vertically or childCount is 0!!"); return false; }
Example 2
Source File: CommonPtrLayout.java From FamilyChat with Apache License 2.0 | 6 votes |
private boolean canScrollDown(View view) { if (android.os.Build.VERSION.SDK_INT < 14) { if (view instanceof AbsListView) { final AbsListView absListView = (AbsListView) view; return absListView.getChildCount() > 0 && (absListView.getLastVisiblePosition() < absListView.getChildCount() - 1 || absListView.getChildAt(absListView.getChildCount() - 1).getBottom() > absListView.getPaddingBottom()); } else { return ViewCompat.canScrollVertically(view, 1) || view.getScrollY() < 0; } } else { return ViewCompat.canScrollVertically(view, 1); } }
Example 3
Source File: DiySwipeRefreshLayout.java From AndroidStudyDemo with GNU General Public License v2.0 | 6 votes |
public boolean canChildScrollDown() { if (android.os.Build.VERSION.SDK_INT < 14) { if (mTarget instanceof AbsListView) { final AbsListView absListView = (AbsListView) mTarget; View lastChild = absListView.getChildAt(absListView.getChildCount() - 1); if (lastChild != null) { return (absListView.getLastVisiblePosition() == (absListView.getCount() - 1)) && lastChild.getBottom() > absListView.getPaddingBottom(); } else { return false; } } else { return mTarget.getHeight() - mTarget.getScrollY() > 0; } } else { return ViewCompat.canScrollVertically(mTarget, 1); } }
Example 4
Source File: Util.java From dynamiclistview with MIT License | 6 votes |
public static int getItemIndexAtLocation(AbsListView listView, int y) { int index = 0; if (listView.getCount() <= 0) return index; int k = listView.getFirstVisiblePosition(); for(int i = k ; i <= listView.getLastVisiblePosition() ; i++) { View view = listView.getChildAt(i - k); if (y > view.getTop() && y < view.getBottom() ) { return index = i; } } return 0; }
Example 5
Source File: SwipyRefreshLayout.java From AndroidStudyDemo with GNU General Public License v2.0 | 6 votes |
public boolean canChildScrollDown() { if (android.os.Build.VERSION.SDK_INT < 14) { if (mTarget instanceof AbsListView) { final AbsListView absListView = (AbsListView) mTarget; try { if (absListView.getCount() > 0) { if (absListView.getLastVisiblePosition() + 1 == absListView.getCount()) { int lastIndex = absListView.getLastVisiblePosition() - absListView.getFirstVisiblePosition(); return absListView.getChildAt(lastIndex).getBottom() == absListView.getPaddingBottom(); } } } catch (Exception e) { e.printStackTrace(); } return true; } else { return true; } } else { return ViewCompat.canScrollVertically(mTarget, 1); } }
Example 6
Source File: SwipeToRefreshLayout.java From SwipeToRefresh with MIT License | 6 votes |
public boolean canChildScrollDown() { if (android.os.Build.VERSION.SDK_INT < 14) { if (mTarget instanceof AbsListView) { final AbsListView absListView = (AbsListView) mTarget; try { if (absListView.getCount() > 0) { if (absListView.getLastVisiblePosition() + 1 == absListView.getCount()) { int lastIndex = absListView.getLastVisiblePosition() - absListView.getFirstVisiblePosition(); return absListView.getChildAt(lastIndex).getBottom() == absListView.getPaddingBottom(); } } } catch (Exception e) { e.printStackTrace(); } return true; } else { return true; } } else { return ViewCompat.canScrollVertically(mTarget, 1); } }
Example 7
Source File: AbsListScrollSize.java From Paralloid with Apache License 2.0 | 6 votes |
/** * This method is by no means accurate, and Will only work to any degree of accuracy if your list items * are the same height. * Otherwise it becomes vastly more difficult to calculate the correct height. * * @param listView listView to get height of, if no adapter is attached then nothing will happen. * @return 0 for failure. */ public static int calculateApproximateHeight(AbsListView listView) { final ListAdapter adapter = listView.getAdapter(); int onScreenHeight = 0, totalHeight = 0; final int totalCount = adapter.getCount(); final int visibleCount = listView.getLastVisiblePosition() - listView.getFirstVisiblePosition(); if (totalCount > 0) { View view; for (int i = 0; i < visibleCount; i++) { // final View view = adapter.getView(0, null, listView); view = listView.getChildAt(i); // view.measure( // View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), // View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); onScreenHeight += view.getMeasuredHeight(); } // Get the average on screen height, then multiply it up. totalHeight = (onScreenHeight / visibleCount) * totalCount; // Add the divider height. if (listView instanceof ListView) { totalHeight += ((ListView) listView).getDividerHeight() * (totalCount - 1); } } return totalHeight; }
Example 8
Source File: AbsListScrollSize.java From 30-android-libraries-in-30-days with Apache License 2.0 | 6 votes |
/** * This method is by no means accurate, and Will only work to any degree of accuracy if your list items * are the same height. * Otherwise it becomes vastly more difficult to calculate the correct height. * * @param listView listView to get height of, if no adapter is attached then nothing will happen. * @return 0 for failure. */ public static int calculateApproximateHeight(AbsListView listView) { final ListAdapter adapter = listView.getAdapter(); int onScreenHeight = 0, totalHeight = 0; final int totalCount = adapter.getCount(); final int visibleCount = listView.getLastVisiblePosition() - listView.getFirstVisiblePosition(); if (totalCount > 0) { View view; for (int i = 0; i < visibleCount; i++) { // final View view = adapter.getView(0, null, listView); view = listView.getChildAt(i); // view.measure( // View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), // View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); onScreenHeight += view.getMeasuredHeight(); } // Get the average on screen height, then multiply it up. totalHeight = (onScreenHeight / visibleCount) * totalCount; // Add the divider height. if (listView instanceof ListView) { totalHeight += ((ListView) listView).getDividerHeight() * (totalCount - 1); } } return totalHeight; }
Example 9
Source File: StatusScrollListener.java From YiBo with Apache License 2.0 | 6 votes |
@Override public void onScrollStateChanged(AbsListView view, int scrollState) { this.scrollState = scrollState; switch (scrollState) { case OnScrollListener.SCROLL_STATE_IDLE: //Log.v(TAG, "已经停止:SCROLL_STATE_IDLE" + "-->" + view.getCount()); Context context = view.getContext(); SheJiaoMaoApplication sheJiaoMao = (SheJiaoMaoApplication) context.getApplicationContext(); if (view.getLastVisiblePosition() == view.getCount() - 1 && sheJiaoMao.isAutoLoadMore()) { view.getChildAt(view.getChildCount() - 1).performClick(); } displayImage(view); break; case OnScrollListener.SCROLL_STATE_TOUCH_SCROLL: //Log.v(TAG, "SCROLL_STATE_TOUCH_SCROLL:当屏幕滚动且用户使用的触碰或手指还在屏幕上时为1"); break; case OnScrollListener.SCROLL_STATE_FLING: //Log.v(TAG, "SCROLL_STATE_FLING:由于用户的操作,屏幕产生惯性滑动时为2"); break; } }
Example 10
Source File: PtrDefaultHandler2.java From android-Ultra-Pull-To-Refresh-With-Load-More-master with MIT License | 6 votes |
public static boolean canChildScrollDown(View view) { if (android.os.Build.VERSION.SDK_INT < 14) { if (view instanceof AbsListView) { final AbsListView absListView = (AbsListView) view; return absListView.getChildCount() > 0 && (absListView.getLastVisiblePosition() < absListView.getChildCount() - 1 || absListView.getChildAt(absListView.getChildCount() - 1).getBottom() > absListView.getPaddingBottom()); } else if (view instanceof ScrollView) { ScrollView scrollView = (ScrollView) view; if (scrollView.getChildCount() == 0) { return false; } else { return scrollView.getScrollY() < scrollView.getChildAt(0).getHeight() - scrollView.getHeight(); } } else { return false; } } else { return view.canScrollVertically(1); } }
Example 11
Source File: SwipyRefreshLayout.java From SwipyRefreshLayout with MIT License | 6 votes |
public boolean canChildScrollDown() { if (android.os.Build.VERSION.SDK_INT < 14) { if (mTarget instanceof AbsListView) { final AbsListView absListView = (AbsListView) mTarget; try { if (absListView.getCount() > 0) { if (absListView.getLastVisiblePosition() + 1 == absListView.getCount()) { int lastIndex = absListView.getLastVisiblePosition() - absListView.getFirstVisiblePosition(); return absListView.getChildAt(lastIndex).getBottom() == absListView.getPaddingBottom(); } } } catch (Exception e) { e.printStackTrace(); } return true; } else { return true; } } else { return ViewCompat.canScrollVertically(mTarget, 1); } }
Example 12
Source File: UIFlexListView.java From Auie with GNU General Public License v2.0 | 6 votes |
@Override public void onScrollStateChanged(AbsListView view, int scrollState) { switch (scrollState) { case OnScrollListener.SCROLL_STATE_IDLE: //控制上拉加载更多 if (isSuspend && view.getLastVisiblePosition() == (view.getCount() - 1)) { mListView.setType(UIListView.TYPE_ONLY_UP_LOADMORD); }else { mListView.setType(UIListView.TYPE_NONE); } break; default: break; } }
Example 13
Source File: CanRefreshLayout.java From CanRefresh with Apache License 2.0 | 5 votes |
private boolean canScrollDown(View view) { if (android.os.Build.VERSION.SDK_INT < 14) { if (view instanceof AbsListView) { final AbsListView absListView = (AbsListView) view; return absListView.getChildCount() > 0 && (absListView.getLastVisiblePosition() < absListView.getChildCount() - 1 || absListView.getChildAt(absListView.getChildCount() - 1).getBottom() > absListView.getPaddingBottom()); } else { return ViewCompat.canScrollVertically(view, 1) || view.getScrollY() < 0; } } else { return ViewCompat.canScrollVertically(view, 1); } }
Example 14
Source File: SlidingLayout.java From CloudReader with Apache License 2.0 | 5 votes |
/** * 判断View是否可以下拉 * * @return canChildScrollDown */ public boolean canChildScrollDown() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { if (mTargetView instanceof AbsListView) { final AbsListView absListView = (AbsListView) mTargetView; return absListView.getChildCount() > 0 && absListView.getAdapter() != null && (absListView.getLastVisiblePosition() < absListView.getAdapter().getCount() - 1 || absListView.getChildAt(absListView.getChildCount() - 1) .getBottom() < absListView.getPaddingBottom()); } else { return ViewCompat.canScrollVertically(mTargetView, 1) || mTargetView.getScrollY() > 0; } } else { return ViewCompat.canScrollVertically(mTargetView, 1); } }
Example 15
Source File: LingjuSwipeRefreshLayout.java From AssistantBySDK with Apache License 2.0 | 5 votes |
public boolean canChildScrollDown() { if (android.os.Build.VERSION.SDK_INT < 14) { if (mTarget instanceof AbsListView) { final AbsListView absListView = (AbsListView) mTarget; return absListView.getChildCount() > 0 && absListView.getLastVisiblePosition() == absListView.getAdapter().getCount() - 1; } else { return mTarget.getScrollY() < 0; } } else { return ViewCompat.canScrollVertically(mTarget, 1); } }
Example 16
Source File: AutoListView.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 5 votes |
private void ifNeedLoad(AbsListView view, int scrollState) { if (!loadEnable) { return; } try { if (scrollState == OnScrollListener.SCROLL_STATE_IDLE && !isLoading && view.getLastVisiblePosition() == view .getPositionForView(footer) && !isLoadFull) { onLoad(); isLoading = true; } } catch (Exception e) { } }
Example 17
Source File: ListViewFeeds.java From rss with GNU General Public License v3.0 | 5 votes |
@Override public void onScrollStateChanged(AbsListView view, int scrollState) { FeedsActivity activity = (FeedsActivity) view.getContext(); if(SCROLL_STATE_TOUCH_SCROLL == scrollState || SCROLL_STATE_IDLE == scrollState) { Adapter adapter = view.getAdapter(); int first = view.getFirstVisiblePosition(); int last = view.getLastVisiblePosition(); for(int i = 0; last - first >= i; i++) { View viewItem = view.getChildAt(i); if(null != viewItem && viewItem.isShown() && 0 <= viewItem.getTop()) { FeedItem item = (FeedItem) adapter.getItem(first + i); activity.readItem(item.m_time); } } } if(SCROLL_STATE_IDLE == scrollState) { AsyncNavigationAdapter.run(activity); } }
Example 18
Source File: ScrollingUtil.java From TwinklingRefreshLayout with Apache License 2.0 | 5 votes |
public static boolean isAbsListViewToBottom(AbsListView absListView) { if (absListView != null && absListView.getAdapter() != null && absListView.getChildCount() > 0 && absListView.getLastVisiblePosition() == absListView.getAdapter().getCount() - 1) { View lastChild = absListView.getChildAt(absListView.getChildCount() - 1); return lastChild.getBottom() <= absListView.getMeasuredHeight(); } return false; }
Example 19
Source File: ScrollStateUtil.java From SimpleProject with MIT License | 5 votes |
/** * AbsListView类型的View是否已滑动到底部 * @param listView * @return */ public static boolean absListViewReachBottom(AbsListView listView) { if (listView.getChildCount() > 0) { int lastItemBottom = listView.getChildAt(listView.getChildCount() - 1).getBottom(); int listHeight = listView.getBottom() - listView.getTop(); return listView.getLastVisiblePosition() == listView.getAdapter().getCount() - 1 && lastItemBottom <= listHeight; } return false; }
Example 20
Source File: ScrollBoundaryUtil.java From CollapsingRefresh with Apache License 2.0 | 5 votes |
public static boolean canScrollDown(View targetView) { if (android.os.Build.VERSION.SDK_INT < 14) { if (targetView instanceof AbsListView) { final AbsListView absListView = (AbsListView) targetView; return absListView.getChildCount() > 0 && (absListView.getLastVisiblePosition() < absListView.getChildCount() - 1 || absListView.getChildAt(absListView.getChildCount() - 1).getBottom() > absListView.getPaddingBottom()); } else { return targetView.getScrollY() < 0; } } else { return targetView.canScrollVertically(1); } }