標籤:android blog http os 使用 ar strong 檔案 div
Android開發時,有時候需要們來載入網狀圖片,我們可以通過api的方式進行載入,但是前幾天做的時候,發現了一個優秀的開源架構,可以協助我們非常簡單便捷的進行圖片的載入,所以記錄一下。
我所用的是:
android-smart-image-view
在github上的地址是:https://github.com/loopj/android-smart-image-view,我們可以直接進行搜尋,github對於我們程式員來說簡直是寶庫啊,一定要能夠擅長應用。
下載下來後,我們把其目錄下的src下的以com開頭的檔案夾拷貝到我們工程中,這樣我們就能引用相應的方法了。
由於我們要顯示一整圖片,所以這裡在main.xml中我們需要定義的組件是。
這裡要看清楚,我的imageview不是系統api下的imageview而是引用的剛才下載的開源的smartimageview,所以這裡的組件定義方式步以前的不一樣,這要能記著。
<com.loopj.android.image.SmartImageView android:id="@+id/siv" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <EditText android:text="" android:id="@+id/et_path" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="請輸入圖片位置" /> <Button android:onClick="click" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="瀏覽" />
然後再acvity中,我們這樣進行按鈕點擊時間的實現。
這裡調用的方法setImageUrl(String url, final Integer fallbackResource, final Integer loadingResource)
url:擷取網狀圖片的地址。
fallbackResource:下載失敗顯示的圖片
loadingResource:下載中顯示的圖片。
public void click(View view){ SmartImageView siv = (SmartImageView) findViewById(R.id.siv); siv.setImageUrl(et_path.getText().toString().trim() ,R.drawable.ic_launcher,R.drawable.ic_launcher); }
這樣很簡單的,我們就實現了,網狀圖片的載入。
Darren
微博:@IT_攻城師
github:@Darren90
出處:http://www.cnblogs.com/fengtengfei/
Android使用開源架構載入圖片