我在交错布局管理器上实现视差效果时遇到了问题,这是我的代码:
actionbarBackgroundDrawable = getResources().getDrawable(R.drawable.dark_actionbar_drawable);
actionbarBackgroundDrawable.setAlpha(0);
getSupportActionBar().setBackgroundDrawable(actionbarBackgroundDrawable);
scrolledDistance = 0;
RecyclerView.OnScrollListener onScrollListener = new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
scrolledDistance += dy;
if (scrolledDistance < initialHeaderHeight) {
float ratio = (float) scrolledDistance / initialHeaderHeight;
int newAlpha = (int)Math.ceil(ratio*255);
//actionbarBackgroundDrawable.setColorFilter(Color.argb(newAlpha, 37, 43, 53), Mode.SRC_OVER);
actionbarBackgroundDrawable.setAlpha(newAlpha);
RelativeLayout.LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, initialHeaderHeight - scrolledDistance);
rlHeader.setLayoutParams(layoutParams);
mImageView.setColorFilter(Color.argb(newAlpha, 37, 43, 53), Mode.SRC_OVER);
}
else
{
//actionbarBackgroundDrawable.setColorFilter(Color.argb(255, 37, 43, 53), Mode.SRC_OVER);
actionbarBackgroundDrawable.setAlpha(255);
mImageView.setColorFilter(Color.argb(255, 37, 43, 53), Mode.SRC_OVER);
RelativeLayout.LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, 0);
rlHeader.setLayoutParams(layoutParams);
}
if(scrolledDistance == 0)
{
RelativeLayout.LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, initialHeaderHeight);
rlHeader.setLayoutParams(layoutParams);
//actionbarBackgroundDrawable.setColorFilter(Color.argb(0, 37, 43, 53), Mode.SRC_OVER);
actionbarBackgroundDrawable.setAlpha(0);
mImageView.setColorFilter(Color.argb(0, 37, 43, 53), Mode.SRC_OVER);
}
}
};
使用网格布局管理器时效果很好,但是在使用交错网格布局管理器时,视图在滚动时会出现扭曲,是否有人可以为其提出解决方案?