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