Android UI開發第二十二篇——android 瀑布流圖片實現

來源:互聯網
上載者:User

    自pinterest使用了瀑布流展示圖片後,有很多應用開始使用瀑布流的方式,像蘑菇街,美麗說。這裡的瀑布流實現使用了開原始碼。

  

layout:

<?xml version="1.0" encoding="utf-8"?><com.dodowaterfall.LazyScrollView xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/waterfall_scroll"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:scrollbars="vertical" >    <LinearLayout        android:id="@+id/waterfall_container"        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:background="@android:color/white" >    </LinearLayout></com.dodowaterfall.LazyScrollView>

   整個瀑布流用的是ScrollView的子類LazyScrollView。這個LazyScrollView中設定了一個監聽器介面,用來監聽ScrollView執行的不同階段。介面如下:

public interface OnScrollListener {void onBottom();void onTop();void onScroll();void onAutoScroll(int l, int t, int oldl, int oldt);}

    對於每一幅圖,都用一個ImageView的子類FlowView來表示。為了不阻塞UI線程,圖片載入和圖片更新都分別用不同的線程來做。這兩個線程都在FlowView中。FlowView提供了載入和更新的介面給Activity調用。瀑布流執行個體的主Activity是MainActivity,常量都儲存在Constants類中,方便維護。


    瀑布流最重要的是圖片的記憶體回收機制,防止發生記憶體溢出的情況(OOM)。


參考:

https://github.com/dodola/android_waterfall

http://developer.android.com/training/displaying-bitmaps/process-bitmap.html

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.