Use Horizontal Scroll in Android WebView

后端 未结 2 780
温柔的废话
温柔的废话 2021-01-24 07:45

I am currently using epublib-core to read epubs and display them in Android WebView with the following code -

webView.loadDataWithBaseU         


        
2条回答
  •  别那么骄傲
    2021-01-24 08:15

    To get horizontal pagination add css attribute to html before loading to WebView

    String html = getBookContent();  // load epub content to String
    
    int density = getResources().getDisplayMetrics().density;
    int width = (int) Math.floor(mWebView.getWidth() / density);
    int height = (int) Math.floor(mWebView.getHeight() / density);
    
    String style= "\n" +
         "";
    
    html = html.replace("", style);
    html = html.replace("%width", String.valueOf(width));
    html = html.replace("%height", String.valueOf(height));
    
     mWebView.loadDataWithBaseURL(baseUrl, html, "text/html", "utf-8", null);
    

提交回复
热议问题