添加文档
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.Canvas;
|
import android.graphics.Color;
|
||||||
import android.graphics.Color;
|
import android.graphics.LinearGradient;
|
||||||
import android.graphics.LinearGradient;
|
import android.graphics.Paint;
|
||||||
import android.graphics.Paint;
|
import android.graphics.PorterDuff;
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuffXfermode;
|
||||||
import android.graphics.PorterDuffXfermode;
|
import android.graphics.Shader;
|
||||||
import android.graphics.Shader;
|
import android.graphics.Xfermode;
|
||||||
import android.graphics.Xfermode;
|
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
|
||||||
|
/**
|
||||||
/**
|
* RecyclerView右側渐变的itemDecoration
|
||||||
* Created by cxf on 2018/1/27.
|
* 渐变参考文档:https://blog.csdn.net/u010126792/article/details/85237085
|
||||||
* RecyclerView右側渐变的itemDecoration
|
* 半透明则是由0→黑的渐变效果
|
||||||
*/
|
* 使用方法: RecyclerView.addItemDecoration(new RightGradual());
|
||||||
|
*/
|
||||||
public class RightGradual extends RecyclerView.ItemDecoration {
|
|
||||||
|
public class RightGradual extends RecyclerView.ItemDecoration {
|
||||||
private Paint mPaint;
|
|
||||||
private Xfermode mXfermode;
|
private Paint mPaint;
|
||||||
private LinearGradient mLinearGradient;
|
private Xfermode mXfermode;
|
||||||
private int mLayerId;
|
private LinearGradient mLinearGradient;
|
||||||
|
private int mLayerId;
|
||||||
public RightGradual() {
|
|
||||||
mPaint = new Paint();
|
public RightGradual() {
|
||||||
mXfermode = new PorterDuffXfermode(PorterDuff.Mode.DST_IN);
|
mPaint = new Paint();
|
||||||
mLinearGradient = null;
|
mXfermode = new PorterDuffXfermode(PorterDuff.Mode.DST_IN);
|
||||||
}
|
mLinearGradient = null;
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public void onDrawOver(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
|
@Override
|
||||||
super.onDrawOver(canvas, parent, state);
|
public void onDrawOver(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
|
||||||
float left=parent.getRight()-parent.getRight()/0.1f;
|
super.onDrawOver(canvas, parent, state);
|
||||||
float top=0f;
|
float left=parent.getRight()-parent.getRight()/0.1f;
|
||||||
float right=parent.getRight();
|
float top=0f;
|
||||||
float bottom=parent.getBottom();
|
float right=parent.getRight();
|
||||||
if(mLinearGradient==null){
|
float bottom=parent.getBottom();
|
||||||
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);
|
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.setXfermode(mXfermode);
|
||||||
//mPaint.setColor(Color.BLUE);
|
mPaint.setShader(mLinearGradient);
|
||||||
canvas.drawRect(left, top,right, bottom, mPaint);
|
//mPaint.setColor(Color.BLUE);
|
||||||
mPaint.setXfermode(null);
|
canvas.drawRect(left, top,right, bottom, mPaint);
|
||||||
canvas.restoreToCount(mLayerId);
|
mPaint.setXfermode(null);
|
||||||
}
|
canvas.restoreToCount(mLayerId);
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
|
@Override
|
||||||
super.onDraw(c, parent, state);
|
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
|
||||||
mLayerId = c.saveLayer(0.0f, 0.0f, (float) parent.getWidth(), (float) parent.getHeight(), mPaint, Canvas.ALL_SAVE_FLAG);
|
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