滚动listView时如何隐藏fab按钮?
我目前正在使用此代码,但只要我触摸屏幕并滚动,它就会隐藏 FAB 按钮,我需要它隐藏 FAB
当前代码:
mListView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if(scrollState == SCROLL_STATE_TOUCH_SCROLL){
floatingActionButton.hide();
}else{
floatingActionButton.show();
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
}
});
答案 0 :(得分:1)
试试这个,您应该使用onScroll
代替onScrollStateChanged
listview.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
// add here your logic like this
// int lastItem = firstVisibleItem + visibleItemCount;
if (firstVisibleItem < 2) {
floatingActionButton.setVisibility(View.INVISIBLE);
}else {
floatingActionButton.setVisibility(View.VISIBLE);
}
}
});