廢話不多直接上代碼
private boolean isShow=true;
nestedScrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
@Override
public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
//上滑 并且 正在顯示底部欄
if (scrollY - oldScrollY > 0 && isShow) {
isShow = false;
//将Y屬性變為底部欄高度 (相當于隐藏了)
View.animate().translationY(View.getHeight());
} else if (scrollY - oldScrollY < 0 && !isShow) {
isShow = true;
View.animate().translationY(0);
}
}
});