美文网首页
CoordinatorLayout appBarLayout内容

CoordinatorLayout appBarLayout内容

作者: 咚咚_Coding | 来源:发表于2022-03-12 14:12 被阅读0次
public void scrollToTop() {
    //解决到顶部无法滑动的问题
    mRecyclerView.scrollToPosition(0);
    //拿到 appbar 的 behavior,让 appbar 滚动
    ViewGroup.LayoutParams layoutParams = appBarLayout.getLayoutParams();
    CoordinatorLayout.Behavior behavior = ((CoordinatorLayout.LayoutParams) layoutParams).getBehavior();
    if (behavior instanceof AppBarLayout.Behavior) {
        AppBarLayout.Behavior appBarLayoutBehavior = (AppBarLayout.Behavior) behavior;
        //拿到下方tabs的y坐标,即为我要的偏移量
        int topAndBottomOffset = appBarLayoutBehavior.getTopAndBottomOffset();
        if (topAndBottomOffset != 0) {
            appBarLayoutBehavior.setTopAndBottomOffset(0);
            appBarLayout.setExpanded(true, true);
        }
    }
}

相关文章

网友评论

      本文标题:CoordinatorLayout appBarLayout内容

      本文链接:https://www.haomeiwen.com/subject/udgkdrtx.html