StaggeredGridView 开源lib
文章demo下载地址
用imageloder去载入网络图片 用StaggeredGridView去显示实现瀑布流。
MainActivity
package com.origamilabs.library;import java.util.ArrayList;import java.util.Collections;import java.util.HashMap;import java.util.LinkedList;import java.util.List;import java.util.Map;import com.example.staggeredgridviewdemo.views.ScaleImageView;import com.nostra13.universalimageloader.core.ImageLoader;import com.nostra13.universalimageloader.core.assist.ImageLoadingListener;import com.nostra13.universalimageloader.core.assist.SimpleImageLoadingListener;import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;import com.origamilabs.library.views.StaggeredGridView;import android.app.Activity;import android.graphics.Bitmap;import android.os.Bundle;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.ImageView;import android.widget.SimpleAdapter;import android.widget.TextView;public class MainActivity extends Activity{ private StaggeredGridView gridView; private ArrayList通过Tappliacation注冊imageloder Tapplication
package com.origamilabs.library;import java.io.File;import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache;import com.nostra13.universalimageloader.core.DisplayImageOptions;import com.nostra13.universalimageloader.core.ImageLoader;import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;import com.nostra13.universalimageloader.core.assist.QueueProcessingType;import com.nostra13.universalimageloader.utils.StorageUtils;import android.app.Application;public class Tapplication extends Application{@Overridepublic void onCreate() { // TODO Auto-generated method stub super.onCreate(); File cacheDir = StorageUtils.getOwnCacheDirectory(getApplicationContext(), "imageloader/Cache");//sdk缓存文件 DisplayImageOptions defaultOptions = new DisplayImageOptions .Builder() .showImageForEmptyUri(R.drawable.ic_launcher) .showImageOnFail(R.drawable.ic_launcher) .cacheInMemory(true) .cacheOnDisc(true) .build(); ImageLoaderConfiguration config = new ImageLoaderConfiguration .Builder(getApplicationContext()) .discCache(new UnlimitedDiscCache(cacheDir)) .defaultDisplayImageOptions(defaultOptions) .discCacheSize(50 * 1024 * 1024)// .discCacheFileCount(100)// .threadPriority(Thread.NORM_PRIORITY - 2) .denyCacheImageMultipleSizesInMemory() .tasksProcessingOrder(QueueProcessingType.LIFO) .writeDebugLogs() .build(); ImageLoader.getInstance().init(config);}}剩下的为StaggeredGridView 的lib代码就不粘了
效果图: