2012-11-17 72 views

回答

3

擴展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變化<ImageViewyour.package.name.MyImageView

//編輯我只是在從memmory寫它,所以可能會有錯別字

+0

我欣賞你的幫助..任何人都可以看看我的代碼,我犯的錯誤..); – xiongdi

+0

我編輯你的代碼,請檢查它,肩膀現在工作:) – Hruskozrout

+0

謝謝你的幫助..我面臨博士的問題awing正在使用屏幕像素位置,而不是圖像視圖..任何建議如何修改的偏移..謝謝 – xiongdi