Android WebView isn't scrollable

前端 未结 6 374
忘掉有多难
忘掉有多难 2021-01-14 04:38

My Android WebView isn\'t scrollable.

XML Code:



        
相关标签:
6条回答
  • 2021-01-14 04:56

    I have found a solution for this, All you need is to put WebView definition in "

    layout/content_my.xml

    " not in "activity_my.xml"

    <WebView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/webView"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />
    

    And inside the MyActivity.java

        WebView webview = (WebView)findViewById(R.id.webView);
        webview.loadUrl("file:///android_asset/index.html");
        webview.setVerticalScrollBarEnabled(true);
        webview.setHorizontalScrollBarEnabled(true);
    
    0 讨论(0)
  • 2021-01-14 05:01

    add this line and it will start working

    webview.getSettings().setJavaScriptEnabled(true);
    

    Hope, this solves your problem?

    0 讨论(0)
  • 2021-01-14 05:05

    Hey I had the Same Problem with webview. It was not scrolling even with the match_parent attribute and very simple code.

    The problem is not in your xml file. Its in your Java file. In java file of that activity Override onPause AND onResume methods and iclude this code

    @Override
    protected void onResume() {
        super.onResume();
        browser.onResume();
    }
    
    @Override
    protected void onPause() {
        super.onPause();
        browser.onPause();
    }
    

    It is very important that you Pause your WebView AND then Resume it again. Hope that will solve your problem.

    0 讨论(0)
  • 2021-01-14 05:13

    I had some other elements in my relative layout, which I switched to invisible. This made my webview not scrollable. My solution was:

    relativelayout.removeallchilds();
    relativelayout.addchild(webview);
    relativelayout.addchild(overlaybutton);
    
    0 讨论(0)
  • 2021-01-14 05:16

    Don't use wrap_content for your height. If your WebView has the same height as its content, then there's never anything to scroll as obviously the content all fits by definition (though given you're loading content dynamically this may not be exactly what's happening). Try setting the height to match_parent or a fixed value.

    0 讨论(0)
  • 2021-01-14 05:19

    I've posted this as a comment as I think this may be a duplicate, but I would look at this question:

    Android WebView Scrollable

    Which provides a few calls which I believe will solve this issue.

    Another issue:

    Try changing your webview from "Wrap Content" to some specific height. Then set the scrollables.

    Try something like 300dp and go from there.

    0 讨论(0)
提交回复
热议问题