假設中間的滑動區域爲NestedScrollView,那麼給NestedScrollView設置滑動監聽事件,當檢測到用戶在向下滑動時隱藏底部欄,上滑時顯示底部欄. 經過屬性動畫來進行設置底部欄的顯示和隱藏.java
//爲使底部欄能滑動隱藏,直接監聽NestedScrollView的滑動事件 向下滑則隱藏 上滑則顯示
mNestedScrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
@Override
public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int
oldScrollX, int oldScrollY) {
//上滑 而且 正在顯示底部欄
if (scrollY - oldScrollY > 0 && isBottomShow) {
isBottomShow = false;
//將Y屬性變爲底部欄高度 (至關於隱藏了)
mBottomView.animate().translationY(mBottomView.getHeight());
} else if (scrollY - oldScrollY < 0 && !isBottomShow) {
isBottomShow = true;
mBottomView.animate().translationY(0);
}
}
});