安卓:画在画布上网页视图 [英] Android: Draw Canvas on Webview

查看:174
本文介绍了安卓:画在画布上网页视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是web视图来显示图像是在我的资源,使用的WebView,因为我需要它是可缩放的。动态我需要能够在图像上画点,它是一个地图。要做到这一点,我试图把在画布上加载的图像的顶部。画布会对它绘制的点。

I am using a WebView to display an image that is in my resources, using a WebView because I need it to be zoomable. Dynamically I need to be able to draw points on the image, it is a map. To do this I am trying to put a canvas on top of the loaded image. The canvas would have the points drawn on it.

mWebView = (WebView)findViewById(R.id.webview);
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.loadUrl("file:///android_res/drawable/map.png");

Canvas c = new Canvas();
c.drawARGB(10, 0, 100, 12);//This is just random. It is where I would draw the points
mWebView.draw(c);

最后3行中的code似乎没有做任何事情。

The last 3 lines in the code do not appear to do anything.

有没有更好的方法去对的WebView的顶部绘制?它甚至有可能这样?

Is there a better way to go about drawing on top of a WebView? Is it even possible this way?

推荐答案

在你最后一行,你给它一个新的画布(这将不会map.png加载)。

In you last line, you are giving it a new canvas (which will not have map.png loaded).

你应该做的是:


  • 创建延伸的WebView一个新类

  • 覆盖它的onDraw()方法,如:

公共类MyWebView扩展的WebView {

public class MyWebView extends WebView{

@覆盖
    保护无效的onDraw(帆布油画){

@Override protected void onDraw(Canvas canvas) {

    super.onDraw(canvas);
            canvas.drawPoint(yourPoint);
}

}

请其变量:

        MyWebView mWebView = new MyWebView(this);
        mWebView.getSettings().setBuiltInZoomControls(true);
        mWebView.loadUrl("file:///android_res/drawable/map.png");

此视图添加到您的主要布局的视图。

add this view to your Main View of your layout.

       myMainView.add(wv);

完成!

这篇关于安卓:画在画布上网页视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆