I have a ViewPager containing a WebView. After some lacks of scroll performance and consulting StackOverflow, I finally disabled hardware acceleration for the WebView. This solves the problem, but now I need to display Youtube videos and other multimedia stuff in my WebView. According to the dokumentation, I need to re-enable hardware acceleration for this :(
Because the scroll issue appears again, I added a ViewPager.OnPageChangeListener() to my ViewPager where I disable hardware acceleration when the pager is scrolling and enable it, when the pager is idle:
pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrollStateChanged(int arg0) {
if(arg0 == ViewPager.SCROLL_STATE_IDLE){
webview.setLayerType(View.LAYER_TYPE_HARDWARE, null);
}
else{
// disable hardware acceleration
webview.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
}
});
It seems to work a bit, but when the hardware acceleration is enabled, the WebView flickers a short time, which is annoying. I have no idea what I can try next... any sugestions?
You should add webview inside the NestedScrollView. In this way i can scroll any html content such as youtube video in the webview without lack of scroll performance.