Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web view Scrolling issue when add hardwareAccelerated is false

I made a web view application in which I show a web site. there is a side navigation bar on web site. When I put hardwareAccelerated=false in manifest then that navigation displays without any problem. When I give value true then that navigation bar displays at a slow speed. My problem is solved when I give value false in manifest to hardwareAccelerated but because of this web view scrolling behaves incorrectly. It gets stuck on some points(jitters) and scrolls back automatically.
What is the possible reason for this behavior?

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    WebView webView=findViewById(R.id.webView);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setUseWideViewPort(true);
    ///CookieManager.getInstance().setCookie("https://helpers.ie/dashboard", "ci_session=ih5amh1qp52puqnqhv8a55iqnh005mqg");
    webView.loadUrl("https://helpers.ie/dashboard");

    webView.setWebViewClient(new WebViewClient() {
        @SuppressWarnings("deprecation")
        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {

        }
        @TargetApi(android.os.Build.VERSION_CODES.M)
        @Override
        public void onReceivedError(WebView view, WebResourceRequest req, WebResourceError rerr) {
            // Redirect to deprecated method, so you can use it in all SDK versions
            onReceivedError(view, rerr.getErrorCode(), rerr.getDescription().toString(), req.getUrl().toString());
        }
    });
}
like image 324
Asad Yasin Avatar asked Feb 16 '26 04:02

Asad Yasin


1 Answers

WebView is noted to have problems with hardware acceleration. According to the android docs, you're enabling and disabling hardware acceleration at the app level. have you tried disabling it only for that particular webview?
this would be done as

webview.setLayerType(View.LAYER_TYPE_SOFTWARE, null);  

what are the results of View.isHardwareAccelerated()? how is the website made? is it static html/css or is it using some sort of js framework?, for eg jquery has issues with hardware acceleration

in comments you've pointed out thi problem doesn't occur on chrome so you can check outchrome custom tab. this can be styled and controlled in your app

String url = ¨https://paul.kinlan.me/¨;
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(this, Uri.parse(url));
like image 81
Karan Harsh Wardhan Avatar answered Feb 17 '26 18:02

Karan Harsh Wardhan