Wro*_*lai 166
编辑:
由于我在我的一个申请中一直在研究这个特定的主题,我可以为这个问题的未来读者写一个扩展的答案.
实现一个OnScrollListener,设置你ListView的onScrollListener,然后你应该能够正确处理事情.
例如:
private int preLast;
// Initialization stuff.
yourListView.setOnScrollListener(this);
// ... ... ...
@Override
public void onScroll(AbsListView lw, final int firstVisibleItem,
final int visibleItemCount, final int totalItemCount)
{
switch(lw.getId())
{
case R.id.your_list_id:
// Make your calculation stuff here. You have all your
// needed info from the parameters of this function.
// Sample calculation to determine if the last
// item is fully visible.
final int lastItem = firstVisibleItem + visibleItemCount;
if(lastItem == totalItemCount)
{
if(preLast!=lastItem)
{
//to avoid multiple calls for last item
Log.d("Last", "Last");
preLast = lastItem;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
小智 68
迟到的答案,但是如果您只是希望检查ListView是否一直向下滚动,而不创建事件监听器,则可以使用此if语句:
if (yourListView.getLastVisiblePosition() == yourListView.getAdapter().getCount() -1 &&
yourListView.getChildAt(yourListView.getChildCount() - 1).getBottom() <= yourListView.getHeight())
{
//It is scrolled all the way down here
}
Run Code Online (Sandbox Code Playgroud)
首先,它检查最后一个可能的位置是否在视野中.然后它检查最后一个按钮的底部是否与ListView的底部对齐.你可以做类似的事情,知道它是否一直在顶部:
if (yourListView.getFirstVisiblePosition() == 0 &&
yourListView.getChildAt(0).getTop() >= 0)
{
//It is scrolled all the way up here
}
Run Code Online (Sandbox Code Playgroud)
t-g*_*gao 17
我这样做的方式:
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE
&& (listView.getLastVisiblePosition() - listView.getHeaderViewsCount() -
listView.getFooterViewsCount()) >= (adapter.getCount() - 1)) {
// Now your listview has hit the bottom
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
}
});
Run Code Online (Sandbox Code Playgroud)
Chr*_*art 10
有效的东西:
if (getListView().getLastVisiblePosition() == (adapter.items.size() - 1))
Run Code Online (Sandbox Code Playgroud)
public void onScrollStateChanged(AbsListView view, int scrollState)
{
if (!view.canScrollList(View.SCROLL_AXIS_VERTICAL) && scrollState == SCROLL_STATE_IDLE)
{
//When List reaches bottom and the list isn't moving (is idle)
}
}
Run Code Online (Sandbox Code Playgroud)
这对我有用.
| 归档时间: |
|
| 查看次数: |
77673 次 |
| 最近记录: |