【发布时间】:2013-12-24 16:52:52
【问题描述】:
我已经在我的应用程序中实现了 webview。它在水平滑动时加载新网页。但是在实现滑动后它不允许网页的垂直滚动。有没有办法实现水平滑动保持垂直滚动??我是新手android 好心建议,这是我的代码:
TestActivity.java
w1 = (WebView) findViewById(R.id.webView1);
w1.setOnTouchListener(new OnSwipeTouchScreen() {
public void onSwipeRight() {
//functioning on right swipe
}
public void onSwipeLeft() {
//functioning on left swipe
}
}
});
OnSwipeTouchScreen.java
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
public class OnSwipeTouchScreen implements OnTouchListener {
@SuppressWarnings("deprecation")
private final GestureDetector gestureDetector = new GestureDetector(new GestureListener());
public boolean onTouch(final View view, final MotionEvent motionEvent) {
return gestureDetector.onTouchEvent(motionEvent);
}
private 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;
try {
float diffX = e2.getX() - e1.getX();
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() {
}
public void onSwipeLeft() {
}
}
【问题讨论】:
-
您可能正在从外部吞下触摸事件,并且它们没有到达 webview。
-
@uʍopǝpısdn 我的滑动事件正常工作那么我的吞咽触摸事件是什么意思?你能描述一下我是安卓新手吗。
-
@ShrutiSharma 我试过你上面的代码。如果您找到了解决方案,请告诉我。