In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the "Android click WebView how to achieve picture zooming and sliding browsing effect", in the daily operation, I believe that many people in Android click WebView how to achieve picture zooming and sliding browsing effect problems have doubts, editor looked up all kinds of information, sorted out a simple and easy to use method of operation, hope to answer everyone's "Android click WebView how to achieve picture zoom and sliding browsing effect" doubt is helpful. Next, please follow the editor to study!
First of all, let's talk about the idea of dealing with this request. first, we need to get the url of all the pictures in the html and save them to the collection. When we click on the picture, jump to
An Activity is displayed in ViewPager, which realizes the effect of sliding browsing. As for image scaling, we need to use the third open source library, PhotoView.
The first is the setting of WebView:
WebView = (WebView) findViewById (R.id.webview); webView.loadUrl (url); WebSettings settings = webView.getSettings (); / / set screen adaptation settings.setLayoutAlgorithm (WebSettings.LayoutAlgorithm.NARROW_COLUMNS); settings.setUseWideViewPort (true); settings.setLoadWithOverviewMode (true); / / prevent Chinese garbled settings.setDefaultTextEncodingName ("UTF-8"); settings.setJavaScriptEnabled (true); / / load js webView.addJavascriptInterface (new JavascriptInterface (this), "imagelistner") WebView.setWebViewClient (new WebViewClient () {/ / webpage jump @ Override public boolean shouldOverrideUrlLoading (WebView view, String url) {view.loadUrl (url); return super.shouldOverrideUrlLoading (view, url);} / / webpage loading ends @ Override public void onPageFinished (WebView view, String url) {super.onPageFinished (view, url); / / after html loading is complete, click the js function addImageClickListner () to add listening images })
Then get the image url in html, save it and open it (the most important thing is to inject the js function to listen and get the url of all images). Here, when I add pictures, I find that pictures are added twice, so I de-duplicate the elements in the list collection:
/ / the injection js function listens to private void addImageClickListner () {/ / traverses all the img nodes in the page, because the url of the images in the nodes is objs[ I] .src, which stores the src of all images. / / set the click event for each picture, objs[ I] .onclick webView.loadUrl ("_ javascript: (function () {" + "var objs = document.getElementsByTagName (\" img\ ");" + "for (var iPlay0witi)
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.