【问题标题】:Horizontal pagination in android webview like iosandroid webview中的水平分页,如ios
【发布时间】:2017-06-15 12:28:25
【问题描述】:
func setupScrollDirection() {
        switch readerConfig.scrollDirection {
        case .vertical, .defaultVertical, .horizontalWithVerticalContent:
            scrollView.isPagingEnabled = false
            paginationMode = .unpaginated
            scrollView.bounces = true
            break
        case .horizontal:
            scrollView.isPagingEnabled = true
            paginationMode = .leftToRight
            paginationBreakingMode = .page
            scrollView.bounces = false
            break
        }
    }

上面的代码有什么替代品吗,我正在尝试横向使用 webview。我已经尝试过像这样的 javaScript

 String varMySheet = "var mySheet = document.styleSheets[0];";

                String addCSSRule = "function addCSSRule(selector, newRule) {"
                        + "ruleIndex = mySheet.cssRules.length;"
                        + "mySheet.insertRule(selector + '{' + newRule + ';}', ruleIndex);"

                        + "}";

             /*   String insertRule1 = "addCSSRule('html', 'padding: 0px; height: "
                        + (webView.getMeasuredHeight() / getResources().getDisplayMetrics().density)
                        + "px; -webkit-column-gap: 0px; -webkit-column-width: "
                        + webView.getMeasuredWidth() + "px;')";*/
                float height=webView.getMeasuredHeight() / getResources().getDisplayMetrics().density;
                    String insertRule1 = "addCSSRule('html', 'margin:0px; padding:0px; height: "
                        + (height)
                        + "px; -webkit-column-gap: 0px; -webkit-column-width: "
                        + webView.getMeasuredWidth() + "px;')";


                webView.loadUrl("javascript:" + varMySheet);
                webView.loadUrl("javascript:" + addCSSRule);
                webView.loadUrl("javascript:" + insertRule1);

但是webview下面有一个空白区域,滚动也没有分页。

【问题讨论】:

  • 你找到解决办法了吗?
  • 不,仍然没有多少解决方案与问题相同

标签: javascript android ios webview uiwebview


【解决方案1】:

添加style="overflow-x: auto; overflow-y: -webkit-paged-x;"到你的身体可以用javascript来完成:

        String js = "javascript:function initialize() { " +
                "var d = document.getElementsByTagName('body')[0];" +
                "d.style.overflow = '-webkit-paged-x';" +
                "}";
        webView.loadUrl(js);
        webView.loadUrl("javascript:initialize()");

在你的网络视图中像这样覆盖onOverScrolled

@Override
protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
    scrollY = 0; // disables vertical scroll
    super.onOverScrolled(scrollX, scrollY, clampedX, clampedY);
}

将导致没有分页的水平滚动。 还没有分页的解决方案。

【讨论】:

    猜你喜欢
    • 2018-06-27
    • 1970-01-01
    • 2020-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多