Issue
I use function drawCircle() to return a ShapeDrawable object which is an oval and use ImageView.setImageDrawable() to set it. But how can I add a 2dp-border to the oval drawable? I tried using GrandientDrawable but no matter how big the value of border thickness is, the border is barely seen on the emulator.
Here's my function drawCircle():
public ShapeDrawable drawCircle (int diameter) {
OvalShape ovalShape = new OvalShape();
ShapeDrawable drawable = new ShapeDrawable(ovalShape);
drawable.getPaint().setColor(getResources().getColor(R.color.textColorHint));
drawable.getPaint().setStyle(Paint.Style.STROKE);
drawable.setIntrinsicHeight(diameter);
drawable.setIntrinsicWidth(diameter);
return drawable;
}
Here's my function setStroke():
public void setStroke(ImageView view) {
GradientDrawable gradientDrawable = new GradientDrawable();
gradientDrawable.setShape(GradientDrawable.OVAL);
gradientDrawable.setStroke(100, Color.WHITE);
view.setBackground(gradientDrawable);
}
Here's how I use it:
// Calculate diameter
int selector_one_diameter = (int)(selector_diameter * 1/6);
// Get ImageView
ImageView one_img = (ImageView) findViewById(R.id.circle_one_selector_img);
// Set drawable
one_img.setImageDrawable(drawCircle(selector_one_diameter));
// Set stroke
setStroke(one_img);
Solution
The best way to work with circular imageview
is working with this library , too easy to work with and it gives you all customizations you are looking for
Answered By - ismail alaoui
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.