现在的位置: 首页 > 综合 > 正文

android 瀑布流实现效果 android 瀑布流效果(仿蘑菇街)

2014年03月29日 ⁄ 综合 ⁄ 共 3630字 ⁄ 字号 评论关闭
 

android 瀑布流效果(仿蘑菇街)

分类: Android 1193人阅读 评论(2) 收藏 举报

我们还是来看一款示例:(蘑菇街)  

                

 看起来很像我们的gridview吧,不过又不像,因为item大小不固定的,看起来是不是别有一番风味,确实如此.就如我们的方角图形,斯通见惯后也就出现了圆角.下面我简单介绍下实现方法.

第一种:

我们在配置文件中定义好列数.如上图也就是3列.我们需要定义三个LinearLayout,然后把获取到的图片add里面就ok了.

main.xml

[java] view
plain
copy

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:background="@android:color/background_light"  
  6.     android:orientation="vertical" >  
  7.   
  8.     <include  
  9.         android:id="@+id/progressbar"  
  10.         layout="@layout/loading" />  
  11.   
  12.     <com.jj.waterfall.LazyScrollView  
  13.         android:id="@+id/lazyscrollview"  
  14.         android:layout_width="fill_parent"  
  15.         android:layout_height="fill_parent"  
  16.         android:layout_weight="1"  
  17.         android:scrollbars="@null" >  
  18.   
  19.         <LinearLayout  
  20.             android:layout_width="fill_parent"  
  21.             android:layout_height="fill_parent"  
  22.             android:background="@android:color/background_light"  
  23.             android:orientation="horizontal"  
  24.             android:padding="2dp" >  
  25.   
  26.             <LinearLayout  
  27.                 android:id="@+id/layout01"  
  28.                 android:layout_width="fill_parent"  
  29.                 android:layout_height="fill_parent"  
  30.                 android:layout_weight="1"  
  31.                 android:orientation="vertical" >  
  32.             </LinearLayout>  
  33.   
  34.             <LinearLayout  
  35.                 android:id="@+id/layout02"  
  36.                 android:layout_width="fill_parent"  
  37.                 android:layout_height="fill_parent"  
  38.                 android:layout_weight="1"  
  39.                 android:orientation="vertical" >  
  40.             </LinearLayout>  
  41.   
  42.             <LinearLayout  
  43.                 android:id="@+id/layout03"  
  44.                 android:layout_width="fill_parent"  
  45.                 android:layout_height="fill_parent"  
  46.                 android:layout_weight="1"  
  47.                 android:orientation="vertical" >  
  48.             </LinearLayout>  
  49.         </LinearLayout>  
  50.     </com.jj.waterfall.LazyScrollView>  
  51.   
  52.     <TextView  
  53.         android:id="@+id/loadtext"  
  54.         android:layout_width="fill_parent"  
  55.         android:layout_height="wrap_content"  
  56.         android:background="@drawable/loading_bg"  
  57.         android:gravity="center"  
  58.         android:padding="10dp"  
  59.         android:text="Loading..."  
  60.         android:textColor="@android:color/background_dark" />  
  61.   
  62. </LinearLayout>  

在这里因为图片很多就把图片放在assets文件中,如果想从网上拉取数据,自己写额外部分.

[java] view
plain
copy

  1. @Override  
  2.     public void onCreate(Bundle savedInstanceState) {  
  3.         super.onCreate(savedInstanceState);  
  4.         InitView();  
  5.   
  6.         assetManager = this.getAssets();  
  7.         // 获取显示图片宽度  
  8.         Image_width = (getWindowManager().getDefaultDisplay().getWidth() - 4) / 3;  
  9.         try {  
  10.             image_filenames = Arrays.asList(assetManager.list("images"));// 获取图片名称  
  11.         } catch (IOException e) {  
  12.             e.printStackTrace();  
  13.         }  
  14.   
  15.         addImage(current_page, count);  
  16.   
  17.     }  

[java] view
plain
copy

  1. /*** 
  2.      * 加载更多 
  3.      *  
  4.      * @param current_page 
  5.      *            当前页数 
  6.      * @param count 
  7.      *            每页显示个数 
  8.      */  
  9.     private void addImage(int current_page, int count) {  
  10.         for (int x = current_page * count; x < (current_page + 1) * count  
  11.                 && x < image_filenames.size(); x++) {  
  12.             addBitMapToImage(image_filenames.get(x), y, x);  
  13.             y++;  
  14.             if (y >= 3)  
  15.                 y = 0;  
  16.         }  
  17.   
  18.     }  

[java] view
plain
copy

  1. /*** 
  2.      * 添加imageview 到layout 

抱歉!评论已关闭.