我试图仅使用android drawables创建以下设计。
我想我可以循环创建线然后覆盖某种渐变层。
我如何有效地进行这种绘图?
答案 0 :(得分:1)
尝试这个自定义Drawable:
class D extends Drawable {
private Paint mPaint;
public D() {
mPaint = new Paint();
}
@Override
protected void onBoundsChange(Rect bounds) {
Bitmap lines = BitmapFactory.decodeResource(getResources(), R.drawable.lines);
Shader shaderA = new BitmapShader(lines, TileMode.REPEAT, TileMode.REPEAT);
Shader shaderB = new LinearGradient(bounds.left, bounds.top, bounds.right, bounds.bottom, Color.BLUE, Color.RED, TileMode.REPEAT);
ComposeShader cs = new ComposeShader(shaderA, shaderB, Mode.SRC_IN);
mPaint.setShader(cs);
}
@Override
public void draw(Canvas canvas) {
canvas.drawPaint(mPaint);
}
@Override
public void setAlpha(int alpha) {
}
@Override
public void setColorFilter(ColorFilter cf) {
}
@Override
public int getOpacity() {
return PixelFormat.TRANSLUCENT;
}
}
其中res / drawable / lines.png如下: