Use WebView to load large images in Android

Source: Internet
Author: User

In Android, loading a picture is a challenging job, especially a large picture beyond the screen, to consider adapting to screen, scrolling and other issues.

The use of web pages can be a good way to screen these problems, WEBVIEW+JS can be very good control of the screen adaptation, there will be no memory overflow situation, to see how to achieve it

Package Com.msn.support.gallery;import Android.annotation.targetapi;import Android.os.bundle;import Android.support.annotation.nullable;import Android.support.v4.app.fragment;import Android.view.GestureDetector; Import Android.view.layoutinflater;import Android.view.motionevent;import Android.view.view;import Android.view.viewgroup;import android.webkit.webview;import com.msn.weiboclient.r;import java.io.File;/** * Created by MSN on 2015/7/13.    */public class Largepicturefragment extends fragment{public static String Arg_url = "URL";    Private String URL; Public largepicturefragment () {} public static largepicturefragment newinstance (String url) {Largepicturefrag        ment fragment = new Largepicturefragment ();        Bundle args = new bundle ();        Args.putstring (Arg_url,url);        Fragment.setarguments (args);    return fragment;        } @Override public void OnCreate (@Nullable Bundle savedinstancestate) {super.oncreate (savedinstancestate); IfGetarguments ()! = null) {URL = getarguments (). getString (Arg_url);         }} @Override public View oncreateview (layoutinflater inflater, ViewGroup container, Bundle savedinstancestate) {        View view = Inflater.inflate (R.layout.fragment_large_pic,container,false);        Final WebView Imgwebview = (WebView) View.findviewbyid (R.id.img_webview);        Imgwebview.setbackgroundcolor (Getresources (). GetColor (r.color.transparent));        Imgwebview.setvisibility (view.invisible);        @TargetApi (one) Imgwebview.setoverscrollmode (view.over_scroll_never);        Imgwebview.getsettings (). Setjavascriptenabled (True);        Imgwebview.getsettings (). Setusewideviewport (True);        Imgwebview.getsettings (). Setloadwithoverviewmode (True);        Imgwebview.getsettings (). Setbuiltinzoomcontrols (True);        Imgwebview.getsettings (). Setdisplayzoomcontrols (false);        Imgwebview.setverticalscrollbarenabled (FALSE); Imgwebview.sethorizontalscrollbarenabled (FALSE);        Imgwebview.setlayertype (view.layer_type_software, NULL);        Imgwebview.setontouchlistener (New Imagewebviewontouch (Imgwebview));        Showcontent (imageloaderutils.getimagedisccached (URL), Imgwebview);    return view;                private void showcontent (file file, WebView Large) {String str1 = "file://" + File.getabsolutepath ()        . replace ("/mnt/sdcard/", "/sdcard/"); String str2 = "

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Use WebView to load large images in Android

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.