Reputation: 41
Can anybody help me with how to draw a circle of specific radius on an ImageView
every time pixel values (centers for the circle to be drawn) are received from another Activity
?
Upvotes: 3
Views: 4841
Reputation: 569
Extend ImageView
and override onDraw(Canvas c)
method - add c.drawCirle(x,y,radius,Paint)
Or for drawing circle you can use pure Canvas as well.
I tried this way but still no luck
public class MyActivity extends Activity {
private MyImageView myImageView;
float x, y;
float [] loc;
float radius = 50;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_location);
myImageView = (MyImageView) findViewById(R.id.mapimageView);
myImageView.setImageResource(R.drawable.mymap);
//Receiving location information(x/y pixels array) from myLocation Activity
Intent i = getIntent();
loc = i.getFloatArrayExtra("Location");
}
public class MyImageView extends ImageView
{
public MyImageView(Context context) {
super(context);
}
// Constructor for inflating via XML
public MyImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint p = new Paint();
x= loc[0];
y=loc[1];
p.setColor(Color.RED);
p.setStrokeWidth(2);
canvas.drawCircle(x, y, radius, p);
}
}
And in xml change <ImageView
to your.package.name.MyImageView
// EDIT Im writing it only from memmory,so there could be typos
Upvotes: 3