Android 底部导航栏动态显示和隐藏(上滑,下拉)
假设中间的滑动区域为NestedScrollView,那么给NestedScrollView设置滑动监听事件,当检测到用户在向下滑动时隐藏底部栏,上滑时显示底部栏. 通过属性动画来进行设置底部栏的显示和隐藏.
//为使底部栏能滑动隐藏,直接监听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);
}
}
});

浙公网安备 33010602011771号