2012-11-17 73 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