public void scrollToTop(boolean flag){
CoordinatorLayout.Behavior behavior = ((CoordinatorLayout.LayoutParams) mAppBarLayout.getLayoutParams()).getBehavior();
if (behavior instanceof AppBarLayout.Behavior) {
AppBarLayout.Behavior appBarLayoutBehavior = (AppBarLayout.Behavior) behavior;
if (true) {
appBarLayoutBehavior.setTopAndBottomOffset(0); //快熟滑动到顶部
} else {
int hight= mAppBarLayout.getHeight();
appBarLayoutBehavior.setTopAndBottomOffset(-hight);//快速滑动实现吸顶效果
}
}
}
CoordinatorLayout+AppBarLayout 布局中实现自动吸顶以及滚动到某一固定位置的效果
最新推荐文章于 2024-01-24 14:44:23 发布