怪我咯2017-04-17 17:36:36
研究了一下自定义了一个
/**
* Created by xg on 2016/8/4.
* 自定义渐变view
*/
public class DrawView extends View {
private LinearGradient linearGradient = null;
private Paint paint = null;
public DrawView(Context context) {
super(context);
}
public DrawView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public DrawView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
linearGradient = new LinearGradient(0, 0, getWidth() - getPaddingRight(), 0,
new int[]{Color.YELLOW, Color.GREEN, Color.TRANSPARENT, Color.WHITE}, null,
Shader.TileMode.REPEAT);
paint = new Paint();
//设置渲染器
paint.setShader(linearGradient);
//绘制圆环
RectF rect = new RectF(0, 0, getWidth() - getPaddingRight(), getHeight() - getPaddingBottom());
canvas.drawRect(rect, paint);
}
}