In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of "how to solve the problem of loading pictures in webView in the front end". The editor shows you the operation process through an actual case. The method of operation is simple and fast, and it is practical. I hope this article "how to solve the problem of loading pictures in webView in the front end" can help you solve the problem.
When a string in html format in the form of xml suddenly appears in the parsing interface, don't panic. Just give it to webview's loaddata method to solve it, but today we are talking about a set of image strings:
Because the URL given does not contain http://, we can't figure it out. We just need to splice the data and then use jsoup to adapt the screen:
Implementation 'org.jsoup:jsoup:1.10.2'
Parsing method:
Public static String formatHtml (String str) {/ / String httpStr= ""; / / String divStr= "$content"; / / String ulStr= "$ul"; String [] split = str.split (">"); StringBuffer sb = new StringBuffer (); for (int I = 0; I
< split.length; i++) { String replace = split[i].replace(""); / / sb.append ("+ replace +" > "+");} / / ulStr=ulStr.replace ("$ul", sb.toString ()); / / divStr=divStr.replace ("$content", ulStr); return sb.toString ();}
At that time, I was thinking that the html fragment would restore the form of a standard div nested unordered list and found that it was still easy to use without so much trouble. Here is the code:
/ / content is the html data String content = t1.getData () .getContent (); / / stitching http: String s = formatHtml (content); / / jsoup adapts screen size Document doc = Jsoup.parse (s); Elements elem_img = doc.getElementsByTag ("img") / / Image adaptive screen if (elem_img.size ()! = 0) {for (Element el_img: elem_img) {el_img.attr ("style", "width:100%");}} / / converted back to the string String S1 = doc.toString () after adaptation / / the following settings are not as good as those after jsoup adaptation / / WebSettings settings = webView.getSettings (); / / settings.setJavaScriptEnabled (true); / / settings.setUseWideViewPort (true); / / key points / / settings.setLoadWithOverviewMode (true); / / Open browser webView.setWebViewClient (new WebViewClient ()) inside webview / / settings.setLayoutAlgorithm (WebSettings.LayoutAlgorithm.SINGLE_COLUMN); / / settings.setDefaultTextEncodingName ("utf-8"); / / webView.loadData (S1, "text/html", "utf-8"); / / webView.loadDataWithBaseURL (null,s1, "text/html", "utf-8", null) Log.i ("tag", "subjectPage 1Result:" + s); that's all for "how to solve the problem of loading pictures on webView in the front end". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.