下面看一个瀑布流是如何实现的
我们需要一个延迟加载的scrollview来让瀑布流动态的呈现,所以要自定义一个scrollview, 监听OnTouchListener事件, 在滑动释放时获取数据, 这里是这么做的: 在手指离开后(MotionEvent.ACTION_UP)发送指定消息, 在handler接受到消息后根据scroll到的位置调用内部接口的相应方法,这种方式是较为常用的。
public interface OnScrollListener{
void onBottom();
void onTop();
void onScroll();
}
防止内存溢出的BitmapCache类的实现, 我觉得不错。
这个是单例模式
public static BitmapCache getInstance() {
if (cache == null) {
cache = new BitmapCache();
}
return cache;
}
下面是获取图片的部分代码
public Bitmap getBitmap(String filename, AssetManager assetManager) {
Bitmap bitmapImage = null;
if (bitmapRefs.containsKey(filename)) {
BtimapRef ref = (BtimapRef) bitmapRefs.get(filename);
bitmapImage = (Bitmap) ref.get();
}
......................................
return bitmapImage;
}
图片最终放在
private final WeakReference<ImageView> imageViewReference;
防止内存溢出
在doInBackground onPostExecute实现异步的主要代码。