仅缩放WebView图像以适应android屏幕

仅缩放WebView图像以适应android屏幕,android,webview,Android,Webview,我有ImageView、TextView和WebView的视图。查看xml: <?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:orientation

我有ImageView、TextView和WebView的视图。查看xml:

<?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:orientation="vertical" >

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
        android:id="@+id/article_details_image_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true" />

    <TextView
        android:id="@+id/article_details_title_text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/article_details_image_view"
        android:layout_margin="5dp" />

    <TextView
        android:id="@+id/article_details_author_text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/article_details_title_text_view"
        android:layout_margin="5dp" />

    <TextView
        android:id="@+id/article_details_date_text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/article_details_author_text_view"
        android:layout_margin="5dp" />

    <WebView
        android:id="@+id/article_details_body_text_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/article_details_date_text_view"
        android:layout_margin="5dp" />
</RelativeLayout>
但什么也没发生,我试过:

WebView browser = (WebView) findViewById(R.id.webview);
browser.getSettings().setLoadWithOverviewMode(true);
browser.getSettings().setUseWideViewPort(true);    
它确实可以将图像从HTML缩放到完美大小,但也可以缩放文本,文本大小变得非常小。如何获得相同的文本大小但缩放的图像

应用程序中的外观:

它在HTML中的外观:


我将帮助您部分解决此问题。 您听说过推出的网站设置、布局算法、文本自动缩放吗 在Android API第19级中。这将解决webview中文本和图像的问题。对于android版本4.4及以上,其工作正常

webView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.TEXT_AUTOSIZING); 
对于以下版本,我还没有找到完美的解决方案。请查看下面的讨论


也可以使用webSettings.setDefaultFontSize((int)fontSize)方法来管理webview中的文本大小。希望这对你有帮助

您需要在html中添加一些样式,例如
img{display:inline;height:auto;max-width:100%;}
我已经使用了您的示例,将max-width设置为device-display-width,这样做很有效。谢谢,这没有改变任何事情。我需要更改我的XML吗?Roo,我已经更新了我的答案,请尝试webSettings.setDefaultFontSize((int)fontSize)方法。
webView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.TEXT_AUTOSIZING);