本文整理汇总了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;
}