Android: sample to show WebView with scrolling

前端 未结 2 1906
死守一世寂寞
死守一世寂寞 2020-12-18 16:48

This should be pretty basic, I just can\'t find out how. I have a webView that shows a page to is too long to show all at once. Right now, it shows the scroll bar, but it

相关标签:
2条回答
  • 2020-12-18 17:14

    did you think about using ScrollView ??

    <ScrollView android:layout_width="fill_parent" 
                android:layout_height="86px" 
                android:id="@+id/scrollTxtDescription"
                android:layout_below="@id/txtLieuPromo1" 
                android:layout_alignLeft="@id/txtLieuPromo1">
    
                <LinearLayout android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/layoutTxtDescription"
                    >
    
                    <WebView android:id="@+id/txtDescription" 
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        />
                </LinearLayout>
            </ScrollView>
    
    0 讨论(0)
  • 2020-12-18 17:16

    i use the next code and it worked for me (tested on android 2.3 and android 4.2 )

    layout:

    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true" >
    
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
    
            <WebView
                android:id="@+id/web_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </FrameLayout>
    
    </ScrollView>
    

    code:

    final WebSettings settings = mWebView.getSettings();
    settings.setDomStorageEnabled(true);
    settings.setJavaScriptEnabled(true);
    mWebView.setVerticalScrollBarEnabled(true);
    
    mWebView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(final WebView view, final String url) {
            super.shouldOverrideUrlLoading(view, url);
            return false;
        }
    
        @Override
        public void onPageFinished(final WebView view, final String url) {
            super.onPageFinished(view, url);
            mWebView.requestLayout();
        }
    
    });
    mWebView.loadUrl(uri);
    
    0 讨论(0)
提交回复
热议问题