Expand appbarlayout when recyclerview is scrolled/fling to top

后端 未结 2 481
春和景丽
春和景丽 2021-02-14 01:23

I implemented a collapsingtoolbar layout with a recyclerview as shown in the sample code attached. My issue is that, when I fling the list downward, it does not go all the way t

2条回答
  •  日久生厌
    2021-02-14 01:58

    I had similar problem and I used a simple trick to expand AppBarLayout when RecyclerView fling to top (you need to have support library >= 23.x.x)

    mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
                @Override
                public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                    super.onScrollStateChanged(recyclerView, newState);
                    if (newState == RecyclerView.SCROLL_STATE_IDLE) {
                        int firstVisiblePosition = linearLayoutManager.findFirstCompletelyVisibleItemPosition();
                        if (firstVisiblePosition == 0) {
                            mAppBarLayout.setExpanded(true, true);
                        }
                    }
                }
    });
    

提交回复
热议问题