heightMove = DisplayUtil.dip2px(this, 220);
this.actionBar = getActionBar();
this.actionBar.setDisplayHomeAsUpEnabled(false);
this.actionBar.setDisplayShowCustomEnabled(true);
View view = getLayoutInflater().inflate(R.layout.transparent_actionbar, null);
this.actionBar.setCustomView(view);
mActionBarBackgroundDrawable = getResources().getDrawable(R.drawable.red);
mActionBarBackgroundDrawable.setAlpha(0);
scrollView.setScrollViewListener(new ObservableScrollView.ScrollViewListener() {
@Override
public void onScrollChanged(ObservableScrollView scrollView, int x, int y, int oldx, int oldy) {
int spot = layoutButton.getTop() - DisplayUtil.dip2px(mContext, 48);
if (y <= spot) {
layoutButtonTop.setVisibility(View.GONE);
} else {
layoutButtonTop.setVisibility(View.VISIBLE);
}
//ActionBar渐变效果
final int headerHeight = heightMove - getActionBar().getHeight();
final float ratio = (float) Math.min(Math.max(y, 0), headerHeight) / headerHeight;
final int newAlpha = (int) (ratio * 255);
mActionBarBackgroundDrawable.setAlpha(newAlpha);
//ActionBar黑色阴影渐变效果
int blackHeight = headerHeight / 2;
float blackRatio = (float) Math.min(Math.max(y, 0), blackHeight) / blackHeight;
int blackAlpha = 255 - (int) (blackRatio * 255);
if (blackAlpha >= 0) {
blackView.setAlpha(blackAlpha);
}
if (newAlpha > 60) {
blackView.setVisibility(View.GONE);
} else {
blackView.setVisibility(View.VISIBLE);
}
}
});