Android用手指在WebView上绘制 [英] Android draw with finger over webView

查看:95
本文介绍了Android用手指在WebView上绘制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何绘制WebView,我希望用户能够在WebView上画圈和涂鸦. gestureoverlayview会很好,但是在用户将手指从屏幕上移开之后,绘制的线条将始终消失.

How can I draw over a webView, I want a user to be able to circle and doodle over the webview. The gestureoverlayview would be good, but the drawn line will always disappear after the user takes their finger off the screen.

我希望用户能够在屏幕上画画,并在手指离开时将画线保留在那里.

I would like the user to be able to draw on the screen and keep the drawn lines there when the finger is lifted off.

非常感谢

推荐答案

您可以将WebView堆叠在某种Canvas之下,该Canvas允许用户在RelativeLayout内部进行触摸绘制.为了说明这一点,这里是从FingerPaint活动内的API Demos项目中获取的示例.

You can stack a WebView underneath a Canvas of some sort that allows the user to paint on it with touch inside of a RelativeLayout. To illustrate this here is an example taken from the API Demos project inside the FingerPaint activity.

我已经稍微修改了该活动,以在MyView后面显示一个WebView.我更改了代码,使MyView的背景具有00 alpha(使其不可见).因此,对于用户来说,好像他们是在浏览器页面的顶部绘制一样.

I've modified that activity slightly to display a WebView behind the MyView. And I altered the code to make the background of the MyView have 00 alpha (make it invisible). So to the user it appears as though they are drawing "on top" of a browser page.

如果尚未拥有,请获取API Demos项目的副本并打开FingerPaint.java文件,该文件位于图形下.打开后,请编辑onCreate()方法,如下所示:

If you don't already have it grab yourself a copy of the API Demos project and open up the FingerPaint.java file, it is under graphics. Once you have that open edit the onCreate() method to look like this:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    RelativeLayout rl = new RelativeLayout(this);
    WebView wv = new WebView(this);
    rl.addView(wv);
    rl.addView(new MyView(this));
    setContentView(rl);
    wv.loadUrl("http://google.com");
    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setDither(true);
    mPaint.setColor(0xFFFF0000);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeJoin(Paint.Join.ROUND);
    mPaint.setStrokeCap(Paint.Cap.ROUND);
    mPaint.setStrokeWidth(12);
    mEmboss = new EmbossMaskFilter(new float[] { 1, 1, 1 },0.4f, 6, 3.5f);
    mBlur = new BlurMaskFilter(8, BlurMaskFilter.Blur.NORMAL);
}

然后找到MyView类的onDraw()方法.在其中,将第一行从以下位置更改:

Then Find the onDraw() method of the MyView class. Inside there change the first line from:

canvas.drawColor(0xFFAAAAAA);

收件人:

canvas.drawColor(0x00AAAAAA);

运行该应用程序,然后单击图形"->"FingerPaint".如果一切顺利,您应该拥有一个可以在其上绘制的Google主页.

Run the app and click graphics->FingerPaint. If all goes well you should have a google home page that you can draw on.

这篇关于Android用手指在WebView上绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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