DevStore首页 > DEV资源 > 源码下载 > 源码详情

ListView动画Android源码

 
anitbird | 2014-11-04 16:18    浏览量(4405)    评论(25)    收藏(20)
功能分类:工具 支持平台:Android 运行环境:Eclipse
开发语言:Java 开发工具:Eclipse 源码大小:4.85MB
下载源码 1379 人下载

源码简介

实现各种列表动画效果。包括卡片式列表(效果图1),Grid View列表(效果图2),列表item逐个淡入显示(效果图3),拖动列表item重新排序(效果图4),滑动删除列表item(效果图5),批量删除列表item(效果图6),展开列表item(效果图7)等等。

源码截图

  • 效果图
  • 效果图
  • 效果图
  • 效果图
  • 效果图
DevStore所有源码来自用户上传分享,版权问题及牵扯到商业纠纷均与DevStore无关。

源码片段

public class ExpandableListItemActivity extends MyListActivity {

	private MyExpandableListItemAdapter mExpandableListItemAdapter;
	private boolean mLimited;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		mExpandableListItemAdapter = new MyExpandableListItemAdapter(this, getItems());
		AlphaInAnimationAdapter alphaInAnimationAdapter = new AlphaInAnimationAdapter(mExpandableListItemAdapter);
		alphaInAnimationAdapter.setAbsListView(getListView());
		getListView().setAdapter(alphaInAnimationAdapter);

		Toast.makeText(this, R.string.explainexpand, Toast.LENGTH_LONG).show();
	}

	private static class MyExpandableListItemAdapter extends ExpandableListItemAdapter {

		private Context mContext;
		private LruCache mMemoryCache;

		/**
		 * Creates a new ExpandableListItemAdapter with the specified list, or an empty list if
		 * items == null.
		 */
		private MyExpandableListItemAdapter(Context context, List items) {
			super(context, R.layout.activity_expandablelistitem_card, R.id.activity_expandablelistitem_card_title, R.id.activity_expandablelistitem_card_content, items);
			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(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 getTitleView(int position, View convertView, ViewGroup parent) {
			TextView tv = (TextView) convertView;
			if (tv == null) {
				tv = new TextView(mContext);
			}
			tv.setText(mContext.getString(R.string.expandorcollapsecard, getItem(position)));
			return tv;
		}

		@Override
		public View getContentView(int position, View convertView, ViewGroup parent) {
			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 onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.menu_expandablelistitem, menu);
		return super.onCreateOptionsMenu(menu);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.menu_expandable_limit:
			mLimited = !mLimited;
			item.setChecked(mLimited);
			mExpandableListItemAdapter.setLimit(mLimited ? 2 : 0);
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}
  •   赞(3) 赞 +1 赞(3) 已赞
  •   收藏(20) 收藏 +1 已收藏 取消
  •   下载(1379)
评论(25)
hupodaofeng

hupodaofeng 2016-04-10 23:12:38

刚好准备入手ListView特效,正好参考参考。谢谢楼主!
回复(0) 赞(0) 赞(1)
烟的寂寞

烟的寂寞 2016-03-17 11:05:27

果断收藏,这么好的东西,谢谢楼主了
回复(0) 赞(0) 赞(1)
诗中

诗中 2015-07-03 15:34:24

怎么导进去有错啊
回复(0) 赞(0) 赞(1)
chu147852

chu147852 2015-05-19 15:18:04

这几个效果做的不错
回复(0) 赞(1) 赞(2)
小熊爱吃肉

小熊爱吃肉 2015-05-14 12:04:34

果断收藏,这么好的东西,谢谢楼主了
回复(0) 赞(0) 赞(1)
  • 推荐
  • 审核
  • 收录
  • 获取活力值

源码上传作者

  • 32 能力值
  • 16 源码
  • 0 评测
  • 1 资料

热门源码