当前位置: 首页>>代码示例>>Java>>正文


Java ListView.setSelectionFromTop方法代码示例

本文整理汇总了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);
        }
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:10,代码来源:ListViewCompatDonut.java

示例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;
}
 
开发者ID:runtimeco,项目名称:Android-DFU-App,代码行数:18,代码来源:UARTLogFragment.java

示例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;
    }
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:55,代码来源:RefreshContentWrapper.java

示例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;
}
 
开发者ID:alibaba,项目名称:LuaViewPlayground,代码行数:21,代码来源:UDBaseListView.java

示例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;
}
 
开发者ID:alibaba,项目名称:LuaViewPlayground,代码行数:20,代码来源:UDBaseListView.java


注:本文中的android.widget.ListView.setSelectionFromTop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。