最近一直在學(xué)習(xí)從遠(yuǎn)程服務(wù)器獲取圖片,開始時(shí)都是手寫這些處理,后來接觸到了smartImageview這個(gè)插件。github獲取地址:https://github.com/loopj/android-smart-p_w_picpath-view
官方原版插件說明
Overview
SmartImageView is a drop-in replacement for Android’s standard ImageView which additionally allows p_w_picpaths 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 p_w_picpaths from a URL
Load p_w_picpaths from the phone’s contact address book
Asynchronous loading of p_w_picpaths, 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()方法,該方法有好幾個(gè)重載方法,用到了這個(gè)
setImageUrl(String url,int fallbackResource)
這個(gè)方法的參數(shù)解析如下:url當(dāng)然是遠(yuǎn)程圖片的地址,第二個(gè)參數(shù)是當(dāng)獲取遠(yuǎn)程圖片失敗時(shí),顯示的圖片,是一個(gè)int類型的res下的圖片的一個(gè)id
在使用時(shí),直接在布局文件里使用SmartImageView就行,這個(gè)類繼承自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.smartp_w_picpathview.loopj.android.p_w_picpath.SmartImageView
android:id="@+id/siv"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
在MainActivity 中
com.yuanlp.smartp_w_picpathviewandroid.support.v7.app.AppCompatActivityandroid.os.Bundlecom.yuanlp.smartp_w_picpathview.loopj.android.p_w_picpath.SmartImageViewMainActivity AppCompatActivity { (Bundle savedInstanceState) { .onCreate(savedInstanceState)setContentView(R.layout.)SmartImageView siv=(SmartImageView) findViewById(R.id.)siv.setImageUrl(R.drawable.)} }
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
當(dāng)前標(biāo)題:SmartImageView初接觸-創(chuàng)新互聯(lián)
當(dāng)前地址:http://chinadenli.net/article46/dhpshg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)頁設(shè)計(jì)公司、小程序開發(fā)、ChatGPT、網(wǎng)站策劃、App開發(fā)、定制開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容