我有一个带工具栏的LinearLayout,工具栏下方的视图(类似于工具栏)和视图下方的列表视图。
当使用CollapsingToolbarLayout滚动列表视图时,我可以隐藏工具栏,是否有任何方法可以隐藏工具栏下方的视图而不会在滚动列表视图时隐藏工具栏?
答案 0 :(得分:0)
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
listView.setOnScrollListener(new OnScrollListener() {
int mLastFirstVisibleItem = 0;
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) { }
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (view.getId() == listView.getId()) {
final int currentFirstVisibleItem = listView.getFirstVisiblePosition();
if (currentFirstVisibleItem > mLastFirstVisibleItem) {
view.setVisibility(View.GONE);//view is the refrene to ur desired view which u want to hide
} else if (currentFirstVisibleItem < mLastFirstVisibleItem) {
view.setVisibility(View.VISIBLE);
}
mLastFirstVisibleItem = currentFirstVisibleItem;
}
}
});