天天看点

Android 配合NestedScrollView 上滑显示 下滑隐藏 底部功能模块

废话不多直接上代码

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);
        }
    }
});