I need to create a rounded ImageView
in Android. Now I use Canvas.clipPath()
but hardware acceleration isn't supported by it. Of course I use View.LAYER_TYPE_SOFTWARE
for this view.
public class RoundedCornerImageView extends MaptrixImageView
{
private final Path clipPath = new Path();
public RoundedCornerImageView(Context context)
{
this(context, null);
}
@SuppressLint("NewApi")
public RoundedCornerImageView(Context context, AttributeSet attrs)
{
super(context, attrs);
if (Build.VERSION.SDK_INT >= 11) {
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
}
@Override
protected void onDraw(Canvas canvas)
{
float radius = ((float) getWidth()) / 2;
clipPath.reset();
clipPath.addCircle(radius, radius, radius, Path.Direction.CW);
canvas.clipPath(clipPath);
super.onDraw(canvas);
}
}
But I would like use hardware acceleration with this View. Can I use the XferMode
class for this ImageView
?