[英]How can I create an image of parallel lines with a gradient in Android?
I am trying to create the following design using only android drawables. 我试图仅使用android drawables创建以下设计。
I imagine I would be able to loop the creation of lines then overlay a gradient layer of some sort. 我想我可以循环创建线,然后覆盖某种渐变层。
How would I go about this kind of drawing efficiently? 我将如何有效地进行这种绘制?
try this custom Drawable: 试试这个自定义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;
}
}
where res/drawable/lines.png is as follows: 其中res / drawable / lines.png如下:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.