3
任何人都可以幫助我如何在每次從另一個Activity
收到像素值(要繪製的圓的中心)時在ImageView
上繪製一個特定半徑的圓?在圖像視圖上繪圖android
任何人都可以幫助我如何在每次從另一個Activity
收到像素值(要繪製的圓的中心)時在ImageView
上繪製一個特定半徑的圓?在圖像視圖上繪圖android
擴展ImageView
和覆蓋onDraw(Canvas c)
方法 - 添加c.drawCirle(x,y,radius,Paint)
或者繪製圓你可以使用純帆布爲好。
我試過這種方式,但仍然沒有運氣
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
//編輯我只是在從memmory寫它,所以可能會有錯別字
我欣賞你的幫助..任何人都可以看看我的代碼,我犯的錯誤..); – xiongdi
我編輯你的代碼,請檢查它,肩膀現在工作:) – Hruskozrout
謝謝你的幫助..我面臨博士的問題awing正在使用屏幕像素位置,而不是圖像視圖..任何建議如何修改的偏移..謝謝 – xiongdi