CoordinatorLayout 嵌套 AppBarLayout RecyclerView ,通过代码控制,使得CoordinatorLayout 自动滑动到tab置顶的位置

有两个方式可以实现

一:调用AppBarLayout,设置间距

val behavior = (appbar_layout.getLayoutParams() as CoordinatorLayout.LayoutParams).getBehavior()
        if (behavior is AppBarLayout.Behavior) {
            var appBarLayoutBehavior = behavior
            var topAndBottomOffset = appBarLayoutBehavior.topAndBottomOffset;
            if (topAndBottomOffset <= 0) {
                appBarLayoutBehavior.topAndBottomOffset = - layout_root.y.toInt()
            }
        }

二:调用现有的api

appbar_layout.setExpanded(false)

 方法二更方便更好

猜你喜欢

转载自www.cnblogs.com/haihai88/p/10788634.html