Fork me on GitHub

标题栏透明度变化

 

 

原理 监听ScrollView的滑动

 

  @Override
    public void onScrollChanged(ObservableScrollView observableScrollView, int x, int y, int oldx, int oldy) {

        Log.d(TAG, "onScrollChanged: "+x+"    "+y+"     "+oldx+"       "+oldy);

        if(y<=0){
            mRlTitleContainer.setBackgroundColor(Color.argb((int) 0, 245, 119, 8));//AGB由相关工具获得,或者美工提供
        }else if(y>0&&y<=mIvTitleBg.getHeight()-mRlTitleContainer.getHeight()){
            float scale = (float) y / (mIvTitleBg.getHeight()-mRlTitleContainer.getHeight());
            float alpha = (255 * scale);
            // title背景透明
            mRlTitleContainer.setBackgroundColor(Color.argb((int) alpha, 245, 119, 8));
        }else {
            mRlTitleContainer.setBackgroundColor(Color.argb((int) 255, 245, 119, 8));
        }
    }

源 码 

https://github.com/ln0491/TitleAlphaDemo

 

posted @ 2016-08-21 18:10  森林森  阅读(546)  评论(0编辑  收藏  举报