滚动布局的监听
scrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
@Override
public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
if (scrollY > oldScrollY) {
// Log.e("=====", "下滑");
Rect scrollBounds = new Rect();
scrollView.getHitRect(scrollBounds);
if (layoutShopping.getLocalVisibleRect(scrollBounds)) {
but1.setChecked(true);
// Log.e("but1", "显示");
} else {
// but2.setChecked(true);
// Log.e("but1", "隐藏");
}
if (layoutDetails.getLocalVisibleRect(scrollBounds)) {
but2.setChecked(true);
// Log.e("11111", "显示");
} else {
// if (but1.isChecked()) {
// } else {
// but2.setChecked(true);
// }
// Log.e("11111", "隐藏");
}
if (layouPinglun.getLocalVisibleRect(scrollBounds)){
but3.setChecked(true);
}
}
if (scrollY < oldScrollY) {
// Log.e("=====", "上滑");
Rect scrollBounds = new Rect();
scrollView.getHitRect(scrollBounds);
if (layoutShopping.getLocalVisibleRect(scrollBounds)) {
but1.setChecked(true);
// Log.e("11111", "显示");
} else {
//but2.setChecked(true);
// Log.e("11111", "隐藏");
}
if (layoutDetails.getLocalVisibleRect(scrollBounds)) {
but2.setChecked(true);
// Log.e("11111", "显示");
} else {
// Log.e("11111", "隐藏");
}
if (layouPinglun.getLocalVisibleRect(scrollBounds)) {
but3.setChecked(true);
// Log.e("11111", "显示");
} else {
// Log.e("11111", "隐藏");
}
}
if (scrollY == 0) {
but1.setChecked(true);
// Log.e("=====", "滑倒顶部");
}
if (scrollY == (v.getChildAt(0).getMeasuredHeight() - v.getMeasuredHeight())) {
// Log.e("=====", "滑倒底部");
}
}
});