GridViewActivity gridview显示时的动画
2015-10-15 14:13
429 查看
package com.duguang.baseanimation.ui.listivew.listviews; import java.util.ArrayList; import java.util.List; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Bundle; import android.support.v4.util.LruCache; import android.support.v7.app.ActionBarActivity; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.GridView; import android.widget.ImageView; import com.duguang.baseanimation.R; import com.duguang.baseanimation.ui.base.BaseActivity; import com.haarman.listviewanimations.ArrayAdapter; import com.haarman.listviewanimations.swinginadapters.prepared.AlphaInAnimationAdapter; public class GridViewActivity extends BaseActivity { @Override public void setView() { setContentView(R.layout.activity_listviews_gridview); GridView gridView = (GridView) findViewById(R.id.activity_gridview_gv); AlphaInAnimationAdapter alphaInAnimationAdapter = new AlphaInAnimationAdapter(new MyAdapter(this, getItems())); alphaInAnimationAdapter.setAbsListView(gridView); gridView.setAdapter(alphaInAnimationAdapter); // getSupportActionBar().setDisplayHomeAsUpEnabled(true); } @Override public void initView() { // TODO Auto-generated method stub } @Override public void setListener() { // TODO Auto-generated method stub } private ArrayList<Integer> getItems() { ArrayList<Integer> items = new ArrayList<Integer>(); for (int i = 0; i < 100; i++) { items.add(i); } return items; } private static class MyAdapter extends ArrayAdapter<Integer> { private Context mContext; private LruCache<Integer, Bitmap> mMemoryCache; public MyAdapter(Context context, List<Integer> list) { super(list); mContext = context; final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); // Use 1/8th of the available memory for this memory cache. final int cacheSize = maxMemory; mMemoryCache = new LruCache<Integer, Bitmap>(cacheSize) { @Override protected int sizeOf(Integer key, Bitmap bitmap) { // The cache size will be measured in kilobytes rather than // number of items. return bitmap.getRowBytes() * bitmap.getHeight() / 1024; } }; } @Override public View getView(int position, View convertView, ViewGroup viewGroup) { ImageView imageView = (ImageView) convertView; if (imageView == null) { imageView = new ImageView(mContext); imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); } int imageResId; switch (getItem(position) % 5) { case 0: imageResId = R.drawable.img_nature1; break; case 1: imageResId = R.drawable.img_nature2; break; case 2: imageResId = R.drawable.img_nature3; break; case 3: imageResId = R.drawable.img_nature4; break; default: imageResId = R.drawable.img_nature5; } Bitmap bitmap = getBitmapFromMemCache(imageResId); if (bitmap == null) { bitmap = BitmapFactory.decodeResource(mContext.getResources(), imageResId); addBitmapToMemoryCache(imageResId, bitmap); } imageView.setImageBitmap(bitmap); return imageView; } private void addBitmapToMemoryCache(int key, Bitmap bitmap) { if (getBitmapFromMemCache(key) == null) { mMemoryCache.put(key, bitmap); } } private Bitmap getBitmapFromMemCache(int key) { return mMemoryCache.get(key); } } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: finish(); return true; default: return super.onOptionsItemSelected(item); } } }
相关文章推荐
- UART 基础知识
- JS 中的闭包
- Http与TCP/IP 协议的关系
- xamarin
- postgresql异步流复制Hot Standby
- iOS原生地图开发进阶——使用导航和附近兴趣点检索
- Hadoop之HBase学习笔记
- 基于jquery的循环左右滚动和上下滚动效果
- CSS3-3D转换
- 哈弗曼编码
- C#数据库操作的用法
- C++ const用法
- Android开发中Parcelable接口的使用方法
- 蓝牙连接外设的流程
- 视频库隆重上线,独家源码等你来领!
- Could not find the main class: org.eclipse.ant.internal.launching.remote.InternalAntRunner. Program
- Java中对List集合的排序
- Intel® Ethernet Connection I217-V 网卡驱动(win10 ,2012)
- 【010】递归函数
- 内部类的四种用法