Android 在不同视图中绘制多个形状

Android 在不同视图中绘制多个形状,android,Android,我创建了一个包含两个图像视图的XML文件。我想在每个视图的中心画两个不同的圆(不同的大小、颜色)。我该怎么做,尤其是坐标。谢谢 创建ImageView的子类。在XML中使用该子类。然后覆盖 public void draw(Canvas canvas){ super.draw(canvas); // do your drawing here // canvas holds the drawable area // use ca

我创建了一个包含两个图像视图的XML文件。我想在每个视图的中心画两个不同的圆(不同的大小、颜色)。我该怎么做,尤其是坐标。谢谢

创建ImageView的子类。在XML中使用该子类。然后覆盖

   public void draw(Canvas canvas){
        super.draw(canvas);
        // do your drawing here
        // canvas holds the drawable area
        // use canvas.drawXXXX methods with basic mathematics to put circles in places you need
   }

希望这能回答您的问题。

您可以使用
形状可拉伸材料来实现这一点

Drawable
文件夹中创建
circle.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
   <solid android:color="@android:color/transparent"/>
   <corners android:radius="12px"/> 
   <stroke  android:width="2dp" android:color="#000000"/> 

</shape>
您可以将此circle.xml用于一个或多个ImageView

<ImageView android:id="@+id/circleimage"  
android:layout_height="150dp" 
android:layout_width="150dp" 
android:src="@drawable/circle">
</ImageView>