Android應(yīng)用實(shí)現(xiàn)瀑布流的方法(附源碼)

2013-06-03 16:09:52來(lái)源:cnblogs作者:游戲阿柴

瀑布流從pinterest流行以后,國(guó)內(nèi)很多網(wǎng)站甚至是app都會(huì)采用這種方式的排版布局。這里介紹一個(gè)android瀑布流的實(shí)現(xiàn)方法,在1萬(wàn)張圖片下可以流暢滑動(dòng),不會(huì)出現(xiàn)內(nèi)存溢出情況。

瀑布流從pinterest流行以后,國(guó)內(nèi)很多網(wǎng)站甚至是app都會(huì)采用這種方式的排版布局。這里介紹一個(gè)android瀑布流的實(shí)現(xiàn)方法,在1萬(wàn)張圖片下可以流暢滑動(dòng),不會(huì)出現(xiàn)內(nèi)存溢出情況。

設(shè)計(jì)思路:

\

之前的作者的自定義view 只有主滑動(dòng)一層,其他的設(shè)置要在相應(yīng)的活動(dòng)設(shè)置,個(gè)人覺(jué)得,重用起來(lái)比較麻煩,所以決定封裝一層.現(xiàn)在定義一個(gè)默認(rèn)的瀑布流只需5步,以下為源碼示意,具體,看源碼...

//1 初始化waterfall

waterfall_scroll = (WaterFallView) findViewById(R.id.waterfall_scroll);

//2 初始化顯示容器

waterfall_container = (LinearLayout) findViewById(R.id.waterfall_container);

//3,設(shè)置滾動(dòng)監(jiān)聽(tīng)

waterfall_scroll.setOnScrollListener(this);

//4,實(shí)例一個(gè)設(shè)置

WaterFallOption fallOption = new WaterFallOption(waterfall_container, 每列寬度, 列數(shù));

//5,提交更改,實(shí)現(xiàn)android瀑布流

waterfall_scroll.commitWaterFall(fallOption, waterfall_scroll);

最后不要忘了監(jiān)聽(tīng)滾動(dòng)到底部的監(jiān)聽(tīng)

@Override public void onBottom() { AddItemToContainer(++(waterfall_scroll.current_page), waterfall_scroll.pageCount); }

已知bug

這里出現(xiàn)的bug,原來(lái)的也有...

  • 滾動(dòng)過(guò)快,導(dǎo)致部分圖片無(wú)法顯示

功能加強(qiáng)

  • 實(shí)現(xiàn)支持URL的方式加載圖片

源碼:https://github.com/youxilua/waterfall4android
 

原作者源碼:https://github.com/dodola/android_waterfall

 

關(guān)鍵詞:Android瀑布流

贊助商鏈接: