我有这个代码,当你向下或向上滚动gridview时,它将隐藏顶部容器。我的问题是它只会在向上或向下滚动然后释放时执行。
如果用户向下滚动而不释放它,我该如何隐藏我的顶部容器。?
mygrid.setOnScrollListener(new OnScrollListener(){
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
// TODO Auto-generated method stub
final GridView lw = (GridView) view;
if (view.getId() == lw.getId()) {
final int currentFirstVisibleItem = lw.getFirstVisiblePosition();
if (currentFirstVisibleItem > mLastFirstVisibleItem) {
mTopContainer.setVisibility(View.GONE);
//Scroll down
} else if (currentFirstVisibleItem < mLastFirstVisibleItem) {
mTopContainer.setVisibility(View.VISIBLE);
//Scroll Up
}
mLastFirstVisibleItem = currentFirstVisibleItem;
}
}
答案 0 :(得分:0)
您可以将滚动逻辑放入OnScrollListener的onScroll方法中:
public abstract void onScroll (AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
//in this method also some parameters are automatically passed, so you don't have to get them from the GridView
}