Android CollapsingToolbarLayout collapse Listener

后端 未结 12 1178
情歌与酒
情歌与酒 2020-12-12 11:37

I am using CollapsingToolBarLayout alongside with AppBarLayout and CoordinatorLayout, and they are working Fine altogether. I set my <

12条回答
  •  旧时难觅i
    2020-12-12 12:33

    This solution works perfectly for me to detect AppBarLayout collapsed or expanded.

    appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
            @Override
            public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
    
                if (Math.abs(verticalOffset)-appBarLayout.getTotalScrollRange() == 0)
                {
                    //  Collapsed
    
    
                }
                else
                {
                    //Expanded
    
    
                }
            }
        });
    

    Used addOnOffsetChangedListener on the AppBarLayout.

提交回复
热议问题