有人可以解释一下或给我链接手势检测器的工作原理吗?我一直在互联网上寻找适当的文档或解释,但我得到的只是源代码.....我试图在我的应用程序,所以我复制粘贴了网络上可用的代码...但是它禁用了滚动和其他功能,所以我想为什么不正确理解代码而不是仅仅复制粘贴它...所以请提供任何帮助非常感谢...请给我提供链接。
顺便说一句,这是我的代码
package i.rock.fb;
import android.os.Bundle;
import android.app.Activity;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MenuInflater;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.WebView;
public class MainActivity extends Activity {
@Override
public boolean onCreateOptionsMenu(android.view.Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater blowup=getMenuInflater();
blowup.inflate(R.menu.main, menu);
return true;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView webView=(WebView)findViewById(R.id.webView);
webView.setWebViewClient(new our());
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("file:///android_asset/www/index.html");
/*@SuppressWarnings("deprecation")
final GestureDetector gestureDetector = new GestureDetector(new GestureListener());
webView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) {
return true;
}
return false;
}
});}
final class GestureListener extends SimpleOnGestureListener {
private static final int SWIPE_THRESHOLD = 100;
private static final int SWIPE_VELOCITY_THRESHOLD = 100;
@Override
public boolean onDown(MotionEvent e) {
return true;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
boolean result = false;WebView webView=(WebView)findViewById(R.id.webView);
try {
float diffY = e2.getY() - e1.getY();
float diffX = e2.getX() - e1.getX();
if (Math.abs(diffX) > Math.abs(diffY)) {
if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
if (diffX > 0) {
onSwipeRight();
} else {
onSwipeLeft();
}
}
}
} catch (Exception exception) {
exception.printStackTrace();
}
return result;
}
}
public void onSwipeRight() {WebView webView=(WebView)findViewById(R.id.webView);
webView.loadUrl("http://www.google.com");
}
public void onSwipeLeft() {WebView webView=(WebView)findViewById(R.id.webView);
webView.loadUrl("http://www.google.com");
*/}}
如果你能纠正它,那会很有帮助,但我仍然建议你告诉我链接,以便我可以阅读更多关于它的信息。我还开设了另一门课程,以便在同一个链接中打开应用程序而不是内置的网络应用程序..
包 i.rock.fb;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class our extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
view.loadUrl(url);
return true;
}}