I found several English tutorials on the net with examples of methods for rounding a bitmap image. But I could not implement them within a fragment. How to proceed in this case?
I found several English tutorials on the net with examples of methods for rounding a bitmap image. But I could not implement them within a fragment. How to proceed in this case?
In my case, I was only able to use one to make a ImageView
round using an external library, in my case the CircleImageView . Home
Just add the dependency on Gradle
:
compile 'de.hdodenhof:circleimageview:2.0.0'
And use CircleImageView
instead of ImageView
in xml:
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="96dp"
android:layout_height="96dp"
android:src="@drawable/profile" // Sua imagem
app:civ_border_width="0dp" // Se quiser pode colocar uma borda na imagem tambem
app:civ_border_color="#FF000000"/> // Cor da borda
For more information, see the official API link.
Good evening,
I tried using android.support.v4.widget.CircleImageView, but I could not, so one solution I found was to implement my own class (MyCircleImageView) inheriting from ImageView. It is a very simple and small class. Can be used in place of ImageView in layout.
/**
* Created by jorlane on 15/05/17.
*/
public class MyCircleImageView extends ImageView {
private Paint paint;
...
Construtores (inicialização, cria o objeto paint)
...
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
paint.setStrokeWidth(2);
paint.setColor(Color.WHITE);
paint.setStyle(Paint.Style.STROKE);
float largura = getWidth();
float altura = getHeight();
float x = largura / 2;
float y = altura / 2;
float raio = 0;
if (largura > altura) {
raio = (altura)/2;
} else {
raio = (largura) / 2;
}
canvas.drawCircle(x, y, raio, paint);
paint.setStrokeWidth(300);
canvas.drawCircle(x, y, raio + 150, paint);
}