I found this post by Romain Guy that's a much easier way to round corners on a tiled bitmap. Here's the short answer:
class CurvedAndTiled extends Drawable {
private final float mCornerRadius;
private final RectF mRect = new RectF();
private final BitmapShader mBitmapShader;
private final Paint mTilePaint;
CurvedAndTiled(
Bitmap bitmap,
float cornerRadius) {
mCornerRadius = cornerRadius;
mBitmapShader = new BitmapShader(bitmap,
Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
mTilePaint = new Paint();
mTilePaint.setAntiAlias(true);
mTilePaint.setShader(mBitmapShader);
}
@Override
protected void onBoundsChange(Rect bounds) {
super.onBoundsChange(bounds);
mRect.set(0, 0, bounds.width(), bounds.height());
}
@Override
public void draw(Canvas canvas) {
canvas.drawRoundRect(mRect, mCornerRadius, mCornerRadius, mTilePaint);
}
@Override
public int getOpacity() {
return PixelFormat.TRANSLUCENT;
}
@Override
public void setAlpha(int alpha) {
mTilePaint.setAlpha(alpha);
}
@Override
public void setColorFilter(ColorFilter cf) {
mTilePaint.setColorFilter(cf);
}
}
You just set your view's background drawable to be one of these guys and you're good to go.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…