1.android 中的gradient最多只支持三种颜色的渐变,我想支持10颜色的渐变有没有其他的方法
I researched and customized one
/** * 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); } }
I researched and customized one