在Android中的谷歌地图上绘制的圆圈内动态添加图像视图

时间:2015-12-10 15:08:27

标签: android

Picture1

Picture2

如果你观察到上面两张图片,图片1中有标记,如果用户点击标记第二张图片将动态提供可用选项,可能是2,3等。

对于第二张图片,我编写了自定义视图并能够绘制圆圈,但无法在圆圈内显示图像。

      public class CustomView extends ViewGroup {

    private Paint paint;

    public CustomView(Context context) {
        super(context);

        // create the Paint and set its color
        paint = new Paint();
        paint.setColor(0xFF1f5b83);
    }


    @Override
    protected void dispatchDraw(Canvas canvas) {
        int width = this.getWidth();
        int height = this.getHeight();
        canvas.drawCircle(width / 2, height / 2-64, 200, paint);
    }




    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
    }

}

出于测试目的,我正在添加文本而不是图像

    public void sendMessage(View view) {
    circleView = new CustomView(this);



    TextView textView = new TextView(this);
    textView.setText("Test");
    textView.setTextColor(Color.WHITE);
    textView.setBackgroundColor(Color.WHITE);

    addContentView(circleView, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    circleView.bringToFront();

}

如何在Java类中添加图像中的图像我的意思是Activity类?

0 个答案:

没有答案