博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
StaggeredGridView+universal-image-loader载入网路图片实现瀑布流
阅读量:5947 次
发布时间:2019-06-19

本文共 5234 字,大约阅读时间需要 17 分钟。

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
> list; private Map
map; String[] imageUrls = new String[] { "http://file.bmob.cn/M00/D9/44/oYYBAFSGZlyAXZjwAAC5ynS9Zww4985471", "http://file.bmob.cn/M00/D8/8F/oYYBAFSFh_WAB_uIAAB4PTlS6rI0966668", "http://file.bmob.cn/M00/D7/56/oYYBAFSBhJSAIdIJAACoNxTDcM44444974", "http://file.bmob.cn/M00/D9/45/oYYBAFSGZvKAdpqWAACKHHYyClU0459660", "http://file.bmob.cn/M00/D9/45/oYYBAFSGZreAEyRSAADfcLFM62U5428980", "http://file.bmob.cn/M00/D9/44/oYYBAFSGZlyAXZjwAAC5ynS9Zww4985471", "http://file.bmob.cn/M00/D9/44/oYYBAFSGZYqAUYxAAADSNZMdbOs5036914", "http://file.bmob.cn/M00/D9/43/oYYBAFSGZRCATj2XAADDaZB1Nbo6433800", "http://file.bmob.cn/M00/D9/41/oYYBAFSGZJKAWXyDAADPOI8iH6Q3523485", "http://file.bmob.cn/M00/D8/8F/oYYBAFSFiE6AbAu2AACfguCRGHY3486277", "http://file.bmob.cn/M00/D8/8F/oYYBAFSFh_WAB_uIAAB4PTlS6rI0966668", "http://file.bmob.cn/M00/D7/57/oYYBAFSBhd-Aa1IiAAC86WAfmc89917549", "http://file.bmob.cn/M00/D7/56/oYYBAFSBhJSAIdIJAACoNxTDcM44444974", "http://file.bmob.cn/M00/D7/55/oYYBAFSBgiKAC2aGAAC4We1hZmk1405980", "http://file.bmob.cn/M00/D7/56/oYYBAFSBgrmAXQ8BAAD665llCTc5545260", "http://file.bmob.cn/M00/D7/56/oYYBAFSBg-CAePQKAAC38mflwMY8903422" }; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); gridView=(StaggeredGridView) findViewById(R.id.gridview);gridView.setItemMargin(10); // set the GridView margin gridView.setPadding(10, 0, 10, 0); ImageAdapter adapter=new ImageAdapter(); gridView.setAdapter(adapter); adapter.notifyDataSetChanged(); } class ImageAdapter extends BaseAdapter { @Override public View getView(final int position, View convertView, ViewGroup parent) { View view = convertView; final ViewHolder holder; if (convertView == null) { LayoutInflater layoutInflator = LayoutInflater.from(MainActivity.this); view = layoutInflator.inflate(R.layout.item, null); holder = new ViewHolder(); holder.image = (ScaleImageView) view.findViewById(R.id.imageView1); view.setTag(holder); } else { holder = (ViewHolder) view.getTag(); } ImageLoader.getInstance().displayImage(imageUrls[position], holder.image ); return view; } @Override public int getCount() { // TODO Auto-generated method stub return imageUrls.length; } @Override public Object getItem(int arg0) { // TODO Auto-generated method stub return imageUrls[arg0]; } @Override public long getItemId(int arg0) { // TODO Auto-generated method stub return arg0; } } private static class ViewHolder { ScaleImageView image; }}
通过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代码就不粘了

效果图:

你可能感兴趣的文章
触发器更新多条数据
查看>>
微信公众平台原创声明功能公测 自媒体原创保护的福音
查看>>
ADF_Advanced ADF系列2_Fusion应用的客制和个性化(Part2)
查看>>
php_linux_centos6.4_安装mysql_apache_php
查看>>
Myeclipse或Eclipse中搭建Easyui环境
查看>>
java的基本数据类型
查看>>
WPF中的CheckBox的_ (underscore / 下划线)丢失
查看>>
正则表达式匹配数字
查看>>
前端模块化
查看>>
QIBO CMS SQL Injection Via Variable Uninitialization In \member\special.php
查看>>
二维数组---模拟斗地主
查看>>
【转】(DT系列六)devicetree中数据和 struct device有什么关系
查看>>
【前端性能】必须要掌握的原生JS实现JQuery
查看>>
mysql系统变量
查看>>
svn cleanup failed–previous operation has not finished; run cleanup if it was interrupted
查看>>
JavaScript 编码规范(中文/Airbnb公司版)
查看>>
DNX/ASP.NET 5的xUnit入门向导
查看>>
正则表达式—匹配连续重复的字符
查看>>
如何在一个月内改善你的生活
查看>>
beyond compare比较工具设置
查看>>