/**
* 根据百分比改变颜色透明度
*/
public int changeAlpha(int color, float fraction) {
int red = Color.red(color);
int green = Color.green(color);
int blue = Color.blue(color);
int alpha = (int) (Color.alpha(color) * fraction);
return Color.argb(alpha, red, green, blue);
}
movieXqScrollview.setOnScrollChangeListener(new View.OnScrollChangeListener() {
@Override
public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
if (scrollY < 190) {
movieTitleBg.setBackgroundColor(changeAlpha(getResources().getColor(R.color.lan), Math.abs(scrollY * 1.0f) / 190));
movieTitleTv.setTextColor(changeAlpha(getResources().getColor(R.color.white), Math.abs(scrollY * 1.0f) / 190));
} else {
movieTitleBg.setBackgroundColor(changeAlpha(getResources().getColor(R.color.lan), 1.0f));
movieTitleTv.setTextColor(changeAlpha(getResources().getColor(R.color.white), 1.0f));
}
}
});