android webview 全屏100%显示图片

栏目: Android · 发布时间: 4年前

内容简介:这里引用 第三方类库使用方法

这里引用 第三方类库

implementation 'org.jsoup:jsoup:1.10.2'

定义 工具 类 HtmlUtils

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

 
public class HtmlUtils {
    /**
     * 将html文本内容中包含img标签的图片,宽度变为屏幕宽度,高度根据宽度比例自适应
     **/
    public static String getNewContent(String htmltext){
        try {
            Document doc= Jsoup.parse(htmltext);
            Elements elements=doc.getElementsByTag("img");
            for (Element element : elements) {
                element.attr("width","100%").attr("height","auto");
            }

            return doc.toString();
        } catch (Exception e) {
            return htmltext;
        }
    }
}

View Code

使用方法


 if(!TextUtils.isEmpty(mCourseDetailRes.getVideo_intro())) {
                   mWebView.setVisibility(View.VISIBLE);
                   WebSettings webSettings = mWebView.getSettings();
                   // 启用JS
                   webSettings.setJavaScriptEnabled(true);
                   webSettings.setUseWideViewPort(true);
                   webSettings.setLoadWithOverviewMode(true);
                   webSettings.setBuiltInZoomControls(false);//开启zoom
                   webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
                   webSettings.setDisplayZoomControls(false);
                   mWebView.setWebViewClient(new WebViewClient());
                   String html=HtmlUtils.getNewContent(mCourseDetailRes.getVideo_intro());
                   mWebView.loadData(html+ "", "text/html", "UTF-8");
               }

View Code

以上所述就是小编给大家介绍的《android webview 全屏100%显示图片》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

HTML5经典实例

HTML5经典实例

Christopher Schmitt、Kyle Simpson / 李强 / 中国电力出版社 / 2013-7 / 48.00元

《HTML5经典实例》对于从中级到高级的Web和移动Web开发者来说是绝佳之选,它帮助你选择对你有用的HTML5功能,并且帮助你体验其他的功能。个技巧的信息十分丰富,都包含了示例代码,并详细讨论了解决方案为何有效以及如何工作。一起来看看 《HTML5经典实例》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

URL 编码/解码
URL 编码/解码

URL 编码/解码

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具