问题描述
那么,有没有一种方法,以WebView控件检测能够做的多点触控缩放,并具有内置的缩放控件,而刷卡?
So is there a way for a webview control to detect a swipe while capable of doing multitouch zoom and having build-in zoom controls?
推荐答案
YES!有这样的一种方式,通过实施的WebView,并创建一个自定义web视图通过这种方式自定义的WebView已构建具有同时多点触摸和建立在控制刷卡检测对于变焦。
YES!There is a way of doing that by implementing WebView and creating a custom WebviewThis way the custom WebView has build inswipe detection having at the same time multi touch and build in controlsfor zoom.
//Declaring the custom Webview and put into a viewflipper
MyWebView[] webview =new MyWebView[2];
flipper = (ViewFlipper) findViewById(R.id.ViewFlipper);
webview[i] = new MyWebView(this);
webview[i].setWebViewClient(new HelloWebViewClient());
webview[i].getSettings().setJavaScriptEnabled(false);
webview[i].setInitialScale(60);
webview[i].getSettings().setBuiltInZoomControls(true);
flipper.addView(webview[0]);
flipper.addView(webview[1]);
和这里是自定义的WebView
and here is the custom webview
public class MyWebView extends WebView {
public MyWebView(Context context) {
super(context);
}
@Override
public boolean onTouchEvent(MotionEvent evt) {
boolean consumed = super.onTouchEvent(evt);
if (isClickable()) {
switch (evt.getAction()) {
case MotionEvent.ACTION_DOWN:
lastTouchX = evt.getX();
lastTouchY = evt.getY();
downXValue = evt.getX();
downTime = evt.getEventTime();
hasMoved = false;
break;
case MotionEvent.ACTION_MOVE:
hasMoved = moved(evt);
break;
case MotionEvent.ACTION_UP:
float currentX = evt.getX();
long currentTime = evt.getEventTime();
float difference = Math.abs(downXValue - currentX);
long time = currentTime - downTime;
Log.i("Touch Event:", "Distance: " + difference + "px Time: " + time + "ms");
if ( (downXValue < currentX) && (time < 220) && (difference > 100) ) {
go_back();
}
if ( (downXValue > currentX) && (time < 220) && (difference > 100) ) {
go_forward();
}
//if (!moved(evt)) performClick();
break;
}
}
return consumed || isClickable();
}
float downXValue;
long downTime;
private float lastTouchX, lastTouchY;
private boolean hasMoved = false;
private boolean moved(MotionEvent evt) {
return hasMoved ||
Math.abs(evt.getX() - lastTouchX) > 10.0 ||
Math.abs(evt.getY() - lastTouchY) > 10.0;
}
}
这就是It.You有内建滑动检测。code是一个有点伪code,并没有清理了,但重写的onTouchEvent在MotionEvent.ACTION_MOVE和案例MotionEvent.ACTION_UP应做的trick.You也可以用时间和不同的界限玩。
And that's It.You have Build in swipe detection.Code is in a bit "pseudocode" and haven't cleaned it up but Overriding the onTouchEvent in MotionEvent.ACTION_MOVE and case MotionEvent.ACTION_UP should do the trick.You can also play with the time and difference bounds .
这篇关于怎样的WebView滑动手势检测与缩放,多点触控启用withing起落的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!