Search the Open source framework Android-smarty-imageviewon GitHub, download the zipped package, and copy the Web Image Viewer layout we wrote earlier.
Unzip the data in the download package, find the Java Source code Copy to our project, we can see that this package has a Smartyimageview.java of custom control, Smartimageview is inherited from ImageView
When we use ImageView in the layout file, we can write directly, because this class is contained in the android.jar package, when using the custom, must add the package name
Gets the smartimageview object, via the Findviewbyid () method
Call the Setimageurl (url,fallbackresource,loadingresource) method of the smartimageview object , Parameters: URL is a String type of picture path, and the other two one is displayed when the download fails and is being downloaded int Types of resources ID
PackageCom.tsh.smartimageview;ImportCom.loopj.android.image.SmartImageView;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.view.Menu;ImportAndroid.view.MenuItem;ImportAndroid.view.View;ImportAndroid.widget.EditText; Public classMainactivityextendsActivity {PrivateEditText Et_path; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); Et_path=(EditText) Findviewbyid (R.id.et_path); } Public voidgetinternetimg (View v) {Smartimageview Siv=(Smartimageview) Findviewbyid (r.id.siv_pic); Siv.setimageurl (Et_path.gettext (). toString (). Trim (), r.drawable.ic_launcher, R.drawable.ic_launcher); }}
[Android] smartimageview& common open Source code