如何在android的所有维度的图像视图上绘制点,如下图所示?

时间:2018-06-01 11:15:20

标签: android xml

我尝试使用此代码,但它不适用于所有维度屏幕。有没有其他方法可以做到这一点。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/main"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <ImageView
        android:id="@+id/image"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:background="@drawable/diabetic_foot_left"
        android:layout_alignParentLeft="true" />
</Linear layout>

<View
        android:id="@+id/view_lf_sensatiion1green"
        android:layout_width="15dp"
        android:layout_height="15dp"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginStart="72dp"
        android:layout_marginTop="150dp"
        android:background="@drawable/circle_green"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="60dp"
        />


</LinearLayout>

circle_green.xml

&#13;
&#13;
<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval"
    android:layout_width="1dp"
    android:layout_height="1dp">

    <solid
        android:color="#00ff00"/>

    <size
        android:width="2dp"
        android:height="2dp"/>
</shape>
&#13;
&#13;
&#13;

我想在图像上放置点,如下所示

enter image description here

我尝试使用此代码,但它不适用于所有维度屏幕。有没有其他方法可以做到这一点。请帮助我,我是新手。

2 个答案:

答案 0 :(得分:1)

我建议查看Canvas。您可以动态地在其他图像上绘制图像,创建custom drawings

类似的东西:

@Override
protected void onDraw(Canvas canvas)
{
    super.onDraw(canvas);
    Bitmap foot = BitmapFactory.decodeResource(getResources(), R.drawable.diabetic_foot_left);
    image = Bitmap.createScaledBitmap(temp, canvas.getWidth(), canvas.getHeight(), true);
    canvas.drawBitmap(image, 0, 0, null);

    Bitmap over = BitmapFactory.decodeResource(getResources(), R.drawable.circle_green);
    image = Bitmap.createScaledBitmap(over, canvas.getWidth(), 
    canvas.getHeight(), true);
    canvas.drawBitmap(image, 0, 0, null);
}

答案 1 :(得分:0)

即使我在我的项目中有相同的要求。这就是我解决的方法。

  1. 采用固定宽度和高度的FrameLayout。
  2. 在此FrameLayout中,使用ImageView放置图像(在您的情况下为脚图像)。
  3. 再采用一个FrameLayout可以在其​​上排列圆圈。通过给定marginLeft,marginTop等来对齐这些圆圈。
  4. 因此具有固定宽度和高度的FrameLayout充当图像和圆形的容器。
  5. 由于容器的宽度,高度是固定的;该解决方案适用于所有设备配置。

我希望这对少数人有帮助。