标题栏透明度变化
@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