我正在将一个网站加载到android网页视图中,我想提高滚动性能。换句话说,我想让用户的滚动更快更流畅。有什么想法吗?提前感谢
发布于 2018-08-23 06:29:51
您是否声明希望在应用程序的清单中使用软件渲染(或通过设置WebView的层类型)?也许可以尝试硬件模式
webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
发布于 2018-09-26 23:18:22
当将WebView嵌入到HorizontalScrollView中的片段中时,我也遇到了缓慢的滚动和不稳定的快速滚动,但似乎在其他情况下也会发生这种情况。经过几天的试验和错误,这里有一个似乎有效的解决方案。关键部分是OnTouchListener;我不认为WebView设置有那么重要。这是违反直觉的,但您必须显式地告诉WebView滚动...看起来像是安卓的窃听器。
WebView myWebView;
VelocityTracker mVelocityTracker;
myWebView.setOnTouchListener(new WebViewOnTouchListener());
private class WebViewOnTouchListener implements View.OnTouchListener {
float currY = 0;
float yVeloc = 0f;
WebView localWebView = myWebView;
@Override
public boolean onTouch(View v, MotionEvent event) {
int index = event.getActionIndex();
int action = event.getActionMasked();
int pointerId = event.getPointerId(index);
switch(action){
case MotionEvent.ACTION_DOWN:
if (mVelocityTracker == null) {
// Retrieve a new VelocityTracker object to watch the velocity
// of a motion.
mVelocityTracker = VelocityTracker.obtain();
} else {
// Reset the velocity tracker back to its initial state.
mVelocityTracker.clear();
}
mVelocityTracker.addMovement(event);
currY = event.getY();
break;
case MotionEvent.ACTION_MOVE:
mVelocityTracker.addMovement(event);
mVelocityTracker.computeCurrentVelocity(1000);
yVeloc = mVelocityTracker.getYVelocity(pointerId);
float y = event.getY();
localWebView.scrollBy(0, (int) (currY - y));
currY = y;
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
localWebView.flingScroll(0, -(int)yVeloc);
break;
}
return true;
}
}
https://stackoverflow.com/questions/51975934
复制相似问题