Toolbar not showing with swipe to refresh

前端 未结 2 540
萌比男神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 01:41

    Update: This bug has been fixed in the version 23.1.1 of support library

    You can set onOffsetChanged listener for your AppBarLayout and prevent to swipe refreshing until AppBarLayout layout offset 0.

    This is good example : https://gist.github.com/blackcj/001a90c7775765ad5212

    0 讨论(0)
  • 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);
    }
    
    0 讨论(0)
提交回复
热议问题