be idle sometimes to,安卓:onScrollStateChanged SCROLL_STATE_IDLE有时不火

I'm running into a bit of a problem. What I'm doing: I've got a ListView which has got some images in it. To make the scrolling smoother I've disabled the images to show up when scrolling. Now there seems to be a bug in Android which sometimes causes the scroll state to not change back from SCROLL_STATE_FLING back to SCROLL_STATE_IDLE, which causes my images to not show up again.

My first thought was to set an onTouchListener and check when I get ACTION_UP, but that doesn't help because the SCROLL_STATE_FLING state is obviously being set after that. So now I've thought I could start a timer when the SCROLL_STATE_FLING state is being set and check after some time if the state is still in fling mode and then invalidate my view. But I don't think that's a very good solution.

Does anyone have a better idea on how I could do that? I've seen this reply but I need a solution for API level < 9 (plus it also sometimes happen when it's not overscrolling)

Here's my code for that:

mList.setOnScrollListener(new OnScrollListener() {

@Override

public void onScrollStateChanged(AbsListView view, int scrollState) {

mListAdapter.setIsScrolling(scrollState != SCROLL_STATE_IDLE);

Log.i(this, "scrollStateChanged" + scrollState);

if (scrollState == SCROLL_STATE_IDLE) {

mList.invalidateViews();

}

}

@Override

public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

}

});

Thanks,

Maria

解决方案

I had the same problem, so my solution was to just detect if the scrollview position has reached the last page and in that case always load the images regardless of the scroll state (since the problem seems to always occur when the user flings to the end of the listview). So modifying your code you would have:

mList.setOnScrollListener(new OnScrollListener() {

@Override

public void onScrollStateChanged(AbsListView view, int scrollState) {

mListAdapter.setIsScrolling(scrollState != SCROLL_STATE_IDLE);

Log.i(this, "scrollStateChanged" + scrollState);

int first = view.getFirstVisiblePosition();

int count = view.getChildCount();

if (scrollState == SCROLL_STATE_IDLE || (first + count > mListAdapter.getCount()) ) {

mList.invalidateViews();

}

}

@Override

public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

}

});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值