Show view when toolbar collapses

后端 未结 2 967
时光取名叫无心
时光取名叫无心 2020-12-23 14:42

I have an activity with a CoordinatorLayout, AppBarLayout, CollapsingToolbarLayout and Toolbar. So, basically, a view tha

2条回答
  •  渐次进展
    2020-12-23 15:23

    Taking a look at the CollapsingToolbarLayout source, the content scrim animations are triggered via an OnOffsetChangedListener on the AppBarLayout. So you could add another one to trigger alpha animations on your text view:

    mListener = new AppBarLayout.OnOffsetChangedListener() {
        @Override
        public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
            if(collapsingToolbar.getHeight() + verticalOffset < 2 * ViewCompat.getMinimumHeight(collapsingToolbar)) {
                hello.animate().alpha(1).setDuration(600);
            } else {
                hello.animate().alpha(0).setDuration(600);
            }
        }
    };
    
    appBar.addOnOffsetChangedListener(mListener);
    

提交回复
热议问题