android 吸顶功能
方式:CoordinatorLayout+AppBarLayout+CollapsingToolbarLayout+recyclerView
AppBarLayout 吸顶
public void scrollToTop(){
CoordinatorLayout.Behavior behavior =
((CoordinatorLayout.LayoutParams) mAppBarLayout.getLayoutParams()).getBehavior();
if (behavior instanceof AppBarLayout.Behavior) {
AppBarLayout.Behavior appBarLayoutBehavior = (AppBarLayout.Behavior) behavior;
int hight = mAppBarLayout.getHeight();
appBarLayoutBehavior.setTopAndBottomOffset(-hight);//快速滑动实现吸顶效果
}
}
// 解决滑动不流畅
recyclerView 设置 setNestedScrollingEnabled(false); 横向的recyclerView
recyclerView 滚动到固定位置
private void scrollPosition(int position) {
recyclerView.scrollToPosition(position);
LinearLayoutManager mLayoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
mLayoutManager.scrollToPositionWithOffset(position, 0);
}
网友评论