任何人都可以帮助我如何在ImageView
每次从另一个接收像素值(要绘制的圆的中心)上绘制一个特定半径的圆Activity
吗?
问问题
4783 次
1 回答
3
扩展ImageView
和覆盖onDraw(Canvas c)
方法 - 添加c.drawCirle(x,y,radius,Paint)
或者对于画圆,你也可以使用纯 Canvas。
我试过这种方式,但仍然没有运气
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);
}
}
并在 xml 中更改<ImageView
为your.package.name.MyImageView
// 编辑我只是从内存中写的,所以可能有错别字
于 2012-11-17T20:55:26.183 回答