直播界面的聊天区域顶部渐变效果
程序员文章站
2022-03-07 16:10:48
/** *聊天区域顶部的渐变效果 * */ Paint mPaint = new Paint(); // 融合器 final Xfermode xfermode = new PorterDuffXfermode(PorterDuff.Mode.DST_IN); mPaint.setXfermode(xfermode); // 创造一个颜色渐变,作为聊天区顶部效......
/**
*聊天区域顶部的渐变效果
*
*/
Paint mPaint = new Paint();
// 融合器
final Xfermode xfermode = new PorterDuffXfermode(PorterDuff.Mode.DST_IN);
mPaint.setXfermode(xfermode);
// 创造一个颜色渐变,作为聊天区顶部效果
LinearGradient linearGradient = new LinearGradient(0.0f, 0.0f, 0.0f, 100.0f, new int[]{0, Color.BLACK}, null, Shader.TileMode.CLAMP);
recyc_pull.addItemDecoration(new RecyclerView.ItemDecoration() {
private int layerId;
// 滑动RecyclerView,渲染之后每次都会回调这个方法,就在这里进行融合
@Override
public void onDrawOver(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
super.onDrawOver(canvas, parent, state);
mPaint.setXfermode(xfermode);
mPaint.setShader(linearGradient);
canvas.drawRect(0.0f, 0.0f, parent.getRight(), 200.0f, mPaint);
mPaint.setXfermode(null);
canvas.restoreToCount(layerId);
}
@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
super.onDraw(c, parent, state);
layerId = c.saveLayer(0.0f, 0.0f, (float) parent.getWidth(), (float) parent.getHeight(), mPaint, Canvas.ALL_SAVE_FLAG);
}
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
super.getItemOffsets(outRect, view, parent, state);
}
});
本文地址:https://blog.csdn.net/a506656675/article/details/107867544