Android使用開源架構載入圖片

來源:互聯網
上載者:User

標籤: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使用開源架構載入圖片

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.