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

ListView特效大集合

2
紫豪 | 2014-10-01 19:36    浏览量(6819)    评论(44)    收藏(15)
功能分类:特效 支持平台:Android 运行环境:Eclipse
开发语言:Java 开发工具:Eclipse 源码大小:2.08MB
下载源码 1228 人下载

源码简介

包含了Item出现动画,滑动删除等功能特效,轻松实现,一步到位。

源码截图

  • 滚动效果
  • 右滑删除
  • 由下而下
  • 飞入效果
DevStore所有源码来自用户上传分享,版权问题及牵扯到商业纠纷均与DevStore无关。

源码片段

public class GoogleCardsActivity extends Activity implements OnDismissCallback {

	private GoogleCardsAdapter mGoogleCardsAdapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_googlecards);

		ListView listView = (ListView) findViewById(R.id.activity_googlecards_listview);

		mGoogleCardsAdapter = new GoogleCardsAdapter(this);
		SwingBottomInAnimationAdapter swingBottomInAnimationAdapter = new SwingBottomInAnimationAdapter(new SwipeDismissAdapter(mGoogleCardsAdapter, this));
		swingBottomInAnimationAdapter.setListView(listView);

		listView.setAdapter(swingBottomInAnimationAdapter);

		mGoogleCardsAdapter.addAll(getItems());
	}

	private ArrayList getItems() {
		ArrayList items = new ArrayList();
		for (int i = 0; i < 100; i++) {
			items.add(i);
		}
		return items;
	}

	@Override
	public void onDismiss(ListView listView, int[] reverseSortedPositions) {
		for (int position : reverseSortedPositions) {
			mGoogleCardsAdapter.remove(position);
		}
	}

	private static class GoogleCardsAdapter extends ArrayAdapter {

		private Context mContext;
		private LruCache mMemoryCache;

		public GoogleCardsAdapter(Context context) {
			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 getView(int position, View convertView, ViewGroup parent) {
			ViewHolder viewHolder;
			View view = convertView;
			if (view == null) {
				view = LayoutInflater.from(mContext).inflate(R.layout.activity_googlecards_card, parent, false);

				viewHolder = new ViewHolder();
				viewHolder.textView = (TextView) view.findViewById(R.id.activity_googlecards_card_textview);
				view.setTag(viewHolder);

				viewHolder.imageView = (ImageView) view.findViewById(R.id.activity_googlecards_card_imageview);
			} else {
				viewHolder = (ViewHolder) view.getTag();
			}

			viewHolder.textView.setText("This is card " + (getItem(position) + 1));
			setImageView(viewHolder, position);

			return view;
		}

		private void setImageView(ViewHolder viewHolder, int position) {
			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);
			}
			viewHolder.imageView.setImageBitmap(bitmap);
		}

		private void addBitmapToMemoryCache(int key, Bitmap bitmap) {
			if (getBitmapFromMemCache(key) == null) {
				mMemoryCache.put(key, bitmap);
			}
		}

		private Bitmap getBitmapFromMemCache(int key) {
			return mMemoryCache.get(key);
		}

		private static class ViewHolder {
			TextView textView;
			ImageView imageView;
		}
	}
}
  •   赞(4) 赞 +1 赞(4) 已赞
  •   收藏(15) 收藏 +1 已收藏 取消
  •   下载(1228)
评论(44)
Tom1982

Tom1982 2017-03-01 14:20:24

看起来还不错,学习下
回复(0) 赞(0) 赞(1)
agag3344

agag3344 2016-08-12 07:45:25

学习开发
谢谢
回复(0) 赞(0) 赞(1)
aiwfor

aiwfor 2016-07-07 15:25:53

看着还不错。。。。。。。。。。。。
回复(0) 赞(0) 赞(1)
854632614

854632614 2016-04-27 11:30:53

谢分享,赞一个
回复(0) 赞(0) 赞(1)
烟的寂寞

烟的寂寞 2016-03-17 11:01:30

特效的效果还不错,谢谢楼主
回复(0) 赞(0) 赞(1)
  • 推荐
  • 审核
  • 收录
  • 获取活力值

源码上传作者

  • 138 能力值
  • 58 源码
  • 10 评测
  • 0 资料

热门源码