添加文档
This commit is contained in:
parent
d7d81bc5a7
commit
7cccc48b80
@ -1,55 +1,56 @@
|
||||
package com.yunbao.live.custom;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.LinearGradient;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffXfermode;
|
||||
import android.graphics.Shader;
|
||||
import android.graphics.Xfermode;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
/**
|
||||
* Created by cxf on 2018/1/27.
|
||||
* RecyclerView右側渐变的itemDecoration
|
||||
*/
|
||||
|
||||
public class RightGradual extends RecyclerView.ItemDecoration {
|
||||
|
||||
private Paint mPaint;
|
||||
private Xfermode mXfermode;
|
||||
private LinearGradient mLinearGradient;
|
||||
private int mLayerId;
|
||||
|
||||
public RightGradual() {
|
||||
mPaint = new Paint();
|
||||
mXfermode = new PorterDuffXfermode(PorterDuff.Mode.DST_IN);
|
||||
mLinearGradient = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDrawOver(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
|
||||
super.onDrawOver(canvas, parent, state);
|
||||
float left=parent.getRight()-parent.getRight()/0.1f;
|
||||
float top=0f;
|
||||
float right=parent.getRight();
|
||||
float bottom=parent.getBottom();
|
||||
if(mLinearGradient==null){
|
||||
mLinearGradient=new LinearGradient(parent.getMeasuredWidth(), 0.0f, 0.0f, 0.0f, new int[]{0, Color.BLACK}, new float[]{0.0f,0.2f}, Shader.TileMode.CLAMP);
|
||||
}
|
||||
mPaint.setXfermode(mXfermode);
|
||||
mPaint.setShader(mLinearGradient);
|
||||
//mPaint.setColor(Color.BLUE);
|
||||
canvas.drawRect(left, top,right, bottom, mPaint);
|
||||
mPaint.setXfermode(null);
|
||||
canvas.restoreToCount(mLayerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
|
||||
super.onDraw(c, parent, state);
|
||||
mLayerId = c.saveLayer(0.0f, 0.0f, (float) parent.getWidth(), (float) parent.getHeight(), mPaint, Canvas.ALL_SAVE_FLAG);
|
||||
}
|
||||
}
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.LinearGradient;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffXfermode;
|
||||
import android.graphics.Shader;
|
||||
import android.graphics.Xfermode;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
/**
|
||||
* RecyclerView右側渐变的itemDecoration
|
||||
* 渐变参考文档:https://blog.csdn.net/u010126792/article/details/85237085
|
||||
* 半透明则是由0→黑的渐变效果
|
||||
* 使用方法: RecyclerView.addItemDecoration(new RightGradual());
|
||||
*/
|
||||
|
||||
public class RightGradual extends RecyclerView.ItemDecoration {
|
||||
|
||||
private Paint mPaint;
|
||||
private Xfermode mXfermode;
|
||||
private LinearGradient mLinearGradient;
|
||||
private int mLayerId;
|
||||
|
||||
public RightGradual() {
|
||||
mPaint = new Paint();
|
||||
mXfermode = new PorterDuffXfermode(PorterDuff.Mode.DST_IN);
|
||||
mLinearGradient = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDrawOver(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
|
||||
super.onDrawOver(canvas, parent, state);
|
||||
float left=parent.getRight()-parent.getRight()/0.1f;
|
||||
float top=0f;
|
||||
float right=parent.getRight();
|
||||
float bottom=parent.getBottom();
|
||||
if(mLinearGradient==null){
|
||||
mLinearGradient=new LinearGradient(parent.getMeasuredWidth(), 0.0f, 0.0f, 0.0f, new int[]{0, Color.BLACK}, new float[]{0.0f,0.2f}, Shader.TileMode.CLAMP);
|
||||
}
|
||||
mPaint.setXfermode(mXfermode);
|
||||
mPaint.setShader(mLinearGradient);
|
||||
//mPaint.setColor(Color.BLUE);
|
||||
canvas.drawRect(left, top,right, bottom, mPaint);
|
||||
mPaint.setXfermode(null);
|
||||
canvas.restoreToCount(mLayerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
|
||||
super.onDraw(c, parent, state);
|
||||
mLayerId = c.saveLayer(0.0f, 0.0f, (float) parent.getWidth(), (float) parent.getHeight(), mPaint, Canvas.ALL_SAVE_FLAG);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user