Toolbar not showing with swipe to refresh

前端 未结 2 544
萌比男神i
萌比男神i 2021-02-08 01:21

I\'m trying to implement collapsing tollbar with swipe to refresh and recyclerview. When I\'m trying to scroll (when recyclerview has only one item) toolbar collapse, but when

2条回答
  •  面向向阳花
    2021-02-08 02:00

    I managed it by adding the following implementation of OnOffsetChangedListener in fragment:

    @Override
    public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
        if (collapsingToolbarLayout.getHeight() + verticalOffset < 2 * ViewCompat.getMinimumHeight(collapsingToolbarLayout)) {
            swipeRefreshLayout.setEnabled(false);
        } else {
            swipeRefreshLayout.setEnabled(true);
        }
    }
    
    @Override
    public void onResume() {
        super.onResume();
        appBarLayout.addOnOffsetChangedListener(this);
    }
    
    @Override
    public void onPause() {
        super.onPause();
        appBarLayout.removeOnOffsetChangedListener(this);
    }
    

提交回复
热议问题