android webview 全屏100%显示图片

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

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

这里引用 第三方类库

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%显示图片》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

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

Mastering Bitcoin

Mastering Bitcoin

Andreas M. Antonopoulos / O'Reilly Media / 2014-12-20 / USD 34.99

Mastering Bitcoin tells you everything you need to know about joining one of the most exciting revolutions since the invention of the web: digital money. Bitcoin is the first successful digital curren......一起来看看 《Mastering Bitcoin》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具