美文网首页高级UI
android 吸顶功能

android 吸顶功能

作者: 月未雪 | 来源:发表于2019-10-31 13:54 被阅读0次

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);

        }

相关文章

网友评论

    本文标题:android 吸顶功能

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