I'm trying to make custom ViewGroup layout shapes, that the layout be star or heart, triangles or even make the lines diagonal.
So the the goal is to make collage view for two or more ImageViews.
Could someone give me a library or a way to do this trick?
You can achieve this by using standard methods of Canvas
and BitmapShader
.
First method could look like this:
@Override protected void onDraw(Canvas canvas) {
//bitmap 01
canvas.save(Canvas.CLIP_SAVE_FLAG);
canvas.clipPath(shape01);
canvas.drawBitmap(bitmap01, 0, 0, paint);
canvas.restore();
//bitmap 02
canvas.save(Canvas.CLIP_SAVE_FLAG);
canvas.clipPath(shape02);
canvas.drawBitmap(bitmap02, 0, 0, paint);
canvas.restore();
}
The second could look like this:
BitmapShader shader01 = new BitmapShader(bitmap01, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
BitmapShader shader02 = new BitmapShader(bitmap02, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
Paint paint01 = new Paint();
Paint paint02 = new Paint();
paint01.setShader(shader01);
paint02.setShader(shader02);
@Override protected void onDraw(Canvas canvas) {
//bitmap 01
canvas.drawPath(path01, paint01);
//bitmap 02
canvas.drawPath(path02, paint02);
}
So you need to define your shapes, load bitmaps and draw them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With