SmartImageView初接觸
最近一直在學習從遠程服務器獲取圖片,開始時都是手寫這些處理,後來接觸到了smartImageview這個插件。github獲取地址:https://github.com/loopj/android-smart-image-view
官方原版插件說明
Overview
SmartImageView is a drop-in replacement for Android’s standard ImageView which additionally allows images to be loaded from URLs or the user’s contact address book. Images are cached to memory and to disk for super fast loading.
Features
Drop-in replacement for
ImageView
Load images from a URL
Load images from the phone’s contact address book
Asynchronous loading of images, loading happens outside the UI thread
Images are cached to memory and to disk for super fast loading
SmartImage
class is easily extendable to load from other sources
其中用到的就是:setImageUrl()方法,該方法有好幾個重載方法,用到了這個
setImageUrl(String url,int fallbackResource)
這個方法的參數解析如下:url當然是遠程圖片的地址,第二個參數是當獲取遠程圖片失敗時,顯示的圖片,是一個int類型的res下的圖片的一個id
在使用時,直接在布局文件裏使用SmartImageView就行,這個類繼承自ImageView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.yuanlp.smartimageview.loopj.android.image.SmartImageView
android:id="@+id/siv"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
在MainActivity 中
com.yuanlp.smartimageviewandroid.support.v7.app.AppCompatActivityandroid.os.Bundlecom.yuanlp.smartimageview.loopj.android.image.SmartImageViewMainActivity AppCompatActivity { (Bundle savedInstanceState) { .onCreate(savedInstanceState)setContentView(R.layout.)SmartImageView siv=(SmartImageView) findViewById(R.id.)siv.setImageUrl(R.drawable.)} }
本文出自 “YuanGuShi” 博客,請務必保留此出處http://cm0425.blog.51cto.com/10819451/1941115
SmartImageView初接觸