@Override public int getLastVisiblePosition() { return mListView.getLastVisiblePosition(); }
/** * 判断是否到了最底部 */ private boolean isBottom() { if (mInternalListView != null && mInternalListView.getAdapter() != null) { return mInternalListView.getLastVisiblePosition() == (mInternalListView.getAdapter().getCount() - 1); } return false; } /**
@Override boolean isShownInList(ListView list, int pos) { return pos >= list.getFirstVisiblePosition() && pos <= list.getLastVisiblePosition(); }
@Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (adapter != null && lvEditTextInfo.getLastVisiblePosition() >= adapter.getCount() - 1) { requestSize += 20; Log.i(TAG, "initEvent lvEditTextInfo.setOnScrollListener( >> onScroll getList(intentType);requestSize = " + requestSize); getList(intentType); } } });
@Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (adapter != null && lvEditTextInfo.getLastVisiblePosition() >= adapter.getCount() - 1) { requestSize += 20; Log.i(TAG, "initEvent lvEditTextInfo.setOnScrollListener( >> onScroll getList(intentType);requestSize = " + requestSize); getList(intentType); } } });
ListView list = getListView(); int start = list.getFirstVisiblePosition(); for(int i=start, j=list.getLastVisiblePosition();i<=j;i++) if(target==list.getItemAtPosition(i)){ View view = list.getChildAt(i-start); list.getAdapter().getView(i, view, list); break; }
private void reprioritizeDownloads() { int lastVisibleItem = listView.getLastVisiblePosition(); if (lastVisibleItem >= 0) { int firstVisibleItem = listView.getFirstVisiblePosition(); adapter.prioritizeViewRange(firstVisibleItem, lastVisibleItem, PROFILE_PICTURE_PREFETCH_BUFFER); } }
ListView list = getListView(); int start = list.getFirstVisiblePosition(); for(int i=start, j=list.getLastVisiblePosition();i<=j;i++) if(target==list.getItemAtPosition(i)){ View view = list.getChildAt(i-start); list.getAdapter().getView(i, view, list); break; }
@Override public void run() { if (lv == null) return; synchronized (this) { int start = lv.getFirstVisiblePosition(); int end = Math.min(lv.getLastVisiblePosition(), list.size()); for (int i = start; i <= end; i++) if (target == list.get(i)) { View view = lv.getChildAt(i - start); getView(i, view, lv); break; } } } });
View lastChild = lv.getChildAt(lv.getChildCount() - 1); return (lv.getAdapter().getCount() - lv.getLastVisiblePosition() - 1) * lastChild.getHeight() + lastChild.getBottom() - lv.getBottom();
ListView listView; Runnable fitsOnScreen = new Runnable() { @Override public void run() { int last = listView.getLastVisiblePosition(); if(last == listView.getCount() - 1 && listView.getChildAt(last).getBottom() <= listView.getHeight()) { // It fits! } else { // It doesn't fit... } } };
private void openMessageAtPosition(int position) { // Scroll message into view if necessary int listViewPosition = adapterToListViewPosition(position); if (listViewPosition != AdapterView.INVALID_POSITION && (listViewPosition < listView.getFirstVisiblePosition() || listViewPosition > listView.getLastVisiblePosition())) { listView.setSelection(listViewPosition); } MessageReference ref = getReferenceForPosition(position); // For some reason the listView.setSelection() above won't do anything when we call // onOpenMessage() (and consequently adapter.notifyDataSetChanged()) right away. So we // defer the call using MessageListHandler. handler.openMessage(ref); }
@Test public void touchEvents() { TouchUtils.scrollToBottom(this, getActivity(), list); getInstrumentation().waitForIdleSync(); Assert.assertEquals(24, list.getLastVisiblePosition()); } }
@Test public void touchEvents() { TouchUtils.scrollToBottom(this, getActivity(), list); getInstrumentation().waitForIdleSync(); Assert.assertEquals(24, list.getLastVisiblePosition()); } }
@Test public void touchEvents() { TouchUtils.scrollToBottom(this, getActivity(), list); getInstrumentation().waitForIdleSync(); Assert.assertEquals(24, list.getLastVisiblePosition()); } }
@Test public void touchEvents() { TouchUtils.scrollToBottom(this, getActivity(), list); getInstrumentation().waitForIdleSync(); Assert.assertEquals(24, list.getLastVisiblePosition()); } }
@Test public void touchEvents() { TouchUtils.scrollToBottom(this, getActivity(), list); getInstrumentation().waitForIdleSync(); Assert.assertEquals(24, list.getLastVisiblePosition()); } }
@Override public int getLastVisiblePosition() { return mListView.getLastVisiblePosition(); }
public static void ensureVisible(ListView listView, int pos) { if (listView == null) { return; } if(pos < 0 || pos >= listView.getCount()) { return; } int first = listView.getFirstVisiblePosition(); int last = listView.getLastVisiblePosition(); if (pos < first) { listView.setSelection(pos); return; } if (pos >= last) { listView.setSelection(1 + pos - (last - first)); return; } }
selection = mRefreshableView.getCount() - 1; scrollToHeight = getFooterSize(); scrollLvToEdge = Math.abs(mRefreshableView.getLastVisiblePosition() - selection) <= 1; break; case PULL_FROM_START: