Fading the whole layout as scrolled up in collapsing bar layout android

后端 未结 2 1072
小鲜肉
小鲜肉 2021-02-02 01:25

Below is the code of my coordinator layout. It works well.

 

        
2条回答
  •  耶瑟儿~
    2021-02-02 01:54

    You can reduce the alpha of the RelativeLayout as you scroll up by hooking up an AppBarLayout.OnOffsetChangedListener to the AppBarLayout. Below is the code I used in my app.

    appBar = (AppBarLayout) findViewById(R.id.app_bar_layout);
    appBar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
            @Override
            public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
    
                relativeLayoutToFadeOut.setAlpha(1.0f - Math.abs(verticalOffset / (float)
                        appBarLayout.getTotalScrollRange()));
    
    
            }
        });
    

提交回复
热议问题