我正在实施材料设计的底部导航栏 https://material.io/guidelines/components/bottom-navigation.html
它建议在向下滚动时,我们应该隐藏栏,并在向上滚动时显示它。
我对如何解决这个问题感到有些迷茫。我是否应该手动执行此操作,或者在视图中内置了一些功能。
我有这种行为吗? (因为底部导航是coord布局的孩子)
答案 0 :(得分:0)
这对我有用。
我用过#34;向上滑动"并且"向下滑动"我的gridview动画。当网格向上滚动然后隐藏bottomNavBar并向下滚动然后显示bottomNavBar。那就是它。
myGridView.setOnTouchListener(this);
int y, initialY, scrollingY, scrolledY;
boolean isVisible = true;
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
y = (int) motionEvent.getRawY();
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
initialY = (int) motionEvent.getRawY();
Log.e("Down===", initialY+"");
break;
case MotionEvent.ACTION_MOVE:
scrollingY = (int) motionEvent.getRawY();
Log.e("Move===", scrollingY+"");
switch (view.getId()) {
case R.id.exploreGridMain:
if(isVisible && initialY > scrolledY) {
bottomNavigationView.startAnimation(slideDown);
slideDown.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
bottomNavigationView.setVisibility(View.GONE);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
isVisible = false;
} else if(!isVisible && initialY < scrolledY){
bottomNavigationView.startAnimation(slideUp);
slideUp.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
bottomNavigationView.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
isVisible = true;
}
break;
}
scrolledY = scrollingY;
break;
case MotionEvent.ACTION_UP:
Log.e("Up===", scrolledY+"-"+y);
break;
}
return false;
}