Reputation: 481
I am trying to create the following design using only 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?
Upvotes: 0
Views: 260
Reputation: 24730
try this custom 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:
Upvotes: 1