本文整理匯總了Java中android.widget.ListView.setSelectionFromTop方法的典型用法代碼示例。如果您正苦於以下問題:Java ListView.setSelectionFromTop方法的具體用法?Java ListView.setSelectionFromTop怎麽用?Java ListView.setSelectionFromTop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.widget.ListView
的用法示例。
在下文中一共展示了ListView.setSelectionFromTop方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: scrollListBy
import android.widget.ListView; //導入方法依賴的package包/類
static void scrollListBy(ListView listView, int y) {
int firstPosition = listView.getFirstVisiblePosition();
if (firstPosition != -1) {
View firstView = listView.getChildAt(0);
if (firstView != null) {
listView.setSelectionFromTop(firstPosition, firstView.getTop() - y);
}
}
}
示例2: onLoadFinished
import android.widget.ListView; //導入方法依賴的package包/類
@Override
public void onLoadFinished(final Loader<Cursor> loader, final Cursor data) {
// Here we have to restore the old saved scroll position, or scroll to the bottom if before adding new events it was scrolled to the bottom.
final ListView list = getListView();
final int position = mLogScrollPosition;
final boolean scrolledToBottom = position == LOG_SCROLLED_TO_BOTTOM || (list.getCount() > 0 && list.getLastVisiblePosition() == list.getCount() - 1);
mLogAdapter.swapCursor(data);
if (position > LOG_SCROLL_NULL) {
list.setSelectionFromTop(position, 0);
} else {
if (scrolledToBottom)
list.setSelection(list.getCount() - 1);
}
mLogScrollPosition = LOG_SCROLL_NULL;
}
示例3: onLoadingFinish
import android.widget.ListView; //導入方法依賴的package包/類
@Override
public AnimatorUpdateListener onLoadingFinish(final RefreshKernel kernel, final int footerHeight, int startDelay, final int duration) {
if (mScrollableView != null && kernel.getRefreshLayout().isEnableScrollContentWhenLoaded()) {
if (!canScrollDown(mScrollableView)) {
return null;
}
if (mScrollableView instanceof AbsListView && !(mScrollableView instanceof ListView) && Build.VERSION.SDK_INT < 19) {
if (startDelay > 0) {
kernel.getRefreshLayout().getLayout().postDelayed(new Runnable() {
@Override
public void run() {
((AbsListView) mScrollableView).smoothScrollBy(footerHeight, duration);
}
}, startDelay);
} else {
((AbsListView) mScrollableView).smoothScrollBy(footerHeight, duration);
}
return null;
}
return new AnimatorUpdateListener() {
int lastValue = kernel.getSpinner();
@Override
public void onAnimationUpdate(ValueAnimator animation) {
int value = (int) animation.getAnimatedValue();
try {
if (mScrollableView instanceof ListView) {
if (Build.VERSION.SDK_INT >= 19) {
((ListView) RefreshContentWrapper.this.mScrollableView).scrollListBy(value - lastValue);
} else {
// ListViewCompat.scrollListBy((ListView) mScrollableView, value - lastValue);
ListView listView = (ListView) RefreshContentWrapper.this.mScrollableView;
final int firstPosition = listView.getFirstVisiblePosition();
if (firstPosition == ListView.INVALID_POSITION) {
return;
}
final View firstView = listView.getChildAt(0);
if (firstView == null) {
return;
}
final int newTop = firstView.getTop() - (value - lastValue);
listView.setSelectionFromTop(firstPosition, newTop);
}
} else {
mScrollableView.scrollBy(0, value - lastValue);
}
} catch (Throwable ignored) {
//根據用戶反饋,此處可能會有BUG
}
lastValue = value;
}
};
}
return null;
}
示例4: scrollToTop
import android.widget.ListView; //導入方法依賴的package包/類
/**
* listview滾動到頂部
*
* @param animate 是否動畫
* @return
*/
public UDBaseListOrRecyclerView scrollToTop(final int offset, final boolean animate) {
final ListView lv = getListView();
if (lv != null) {
if (animate) {
if (lv.getFirstVisiblePosition() > 7) {//hack fast scroll
lv.setSelection(7);
}
lv.smoothScrollToPositionFromTop(0, offset);
} else {
lv.setSelectionFromTop(0, offset);
}
}
return this;
}
示例5: scrollToItem
import android.widget.ListView; //導入方法依賴的package包/類
/**
* listview滾動到某個位置
*
* @param section
* @param rowInSection
* @param offset
* @return
*/
public UDBaseListOrRecyclerView scrollToItem(final int section, final int rowInSection, final int offset, final boolean animate) {
final ListView lv = getListView();
if (lv != null) {
if (animate) {
lv.smoothScrollToPositionFromTop(getPositionBySectionAndRow(section, rowInSection), offset);
} else {
lv.setSelectionFromTop(getPositionBySectionAndRow(section, rowInSection), offset);
}
}
return this;
}