如何使用x和y坐标在图像上显示图像

时间:2014-04-09 07:13:16

标签: android imageview

在我的项目中,我想使用x和y坐标在地图图像上显示图像。下面的图像来自具有特定高度和宽度的Web服务。

enter image description here

还从Web服务获取 x y 坐标的数组。通过使用这些坐标,我想在该地图图像上显示图像,如下图所示

enter image description here

这就是我设计xml的原因,如下所示

<ScrollView 
    android:background="#b1cdc4"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent">
    <RelativeLayout 
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        >
        <ImageView 
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_centerInParent="true"/>
    </RelativeLayout>
</ScrollView>

所以我的问题是如何以特定的高度和宽度以编程方式设置地图图像。在该地图图像中如何使用x和y坐标显示图像。所以请建议我如何做到这一点。感谢所有提前..

1 个答案:

答案 0 :(得分:0)

我建议您继承ImageView并覆盖onDraw()方法。 您可以直接绘制到Canvas。像这样......

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas); //this will draw the image
    drawPins(canvas); // now take the canvas and draw your pins
}

关于绘制到画布,您可以在网上找到很多教程,甚至可以在SO上找到。

相关问题