GoogleCardsActivity 效果很好
来源:互联网 发布:网络通,浏览器打不开 编辑:程序博客网 时间:2024/06/06 01:00
/* * Copyright 2013 Niek Haarman * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.duguang.baseanimation.ui.listivew.listviews;import java.util.ArrayList;import android.content.Context;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.os.Bundle;import android.support.v4.util.LruCache;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.AbsListView;import android.widget.ImageView;import android.widget.ListView;import android.widget.TextView;import com.duguang.baseanimation.R;import com.duguang.baseanimation.ui.base.BaseActivity;import com.haarman.listviewanimations.ArrayAdapter;import com.haarman.listviewanimations.itemmanipulation.OnDismissCallback;import com.haarman.listviewanimations.itemmanipulation.SwipeDismissAdapter;import com.haarman.listviewanimations.swinginadapters.prepared.SwingBottomInAnimationAdapter;public class GoogleCardsActivity extends BaseActivity implements OnDismissCallback { private GoogleCardsAdapter mGoogleCardsAdapter; @Override public void setView() { setContentView(R.layout.activity_listviews_googlecards); } @Override public void initView() { ListView listView = (ListView) findViewById(R.id.activity_googlecards_listview); mGoogleCardsAdapter = new GoogleCardsAdapter(this); SwingBottomInAnimationAdapter swingBottomInAnimationAdapter = new SwingBottomInAnimationAdapter(new SwipeDismissAdapter(mGoogleCardsAdapter, this)); swingBottomInAnimationAdapter.setAbsListView(listView); listView.setAdapter(swingBottomInAnimationAdapter); mGoogleCardsAdapter.addAll(getItems()); } @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; } @Override public void onDismiss(AbsListView listView, int[] reverseSortedPositions) { for (int position : reverseSortedPositions) { mGoogleCardsAdapter.remove(position); } } private static class GoogleCardsAdapter extends ArrayAdapter<Integer> { private Context mContext; private LruCache<Integer, Bitmap> 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<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 parent) { ViewHolder viewHolder; View view = convertView; if (view == null) { view = LayoutInflater.from(mContext).inflate(R.layout.activity_listviews_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; } }}
0 0
- GoogleCardsActivity 效果很好
- 很好玩的滚动效果
- 很好玩的滚动效果
- 很好的菜单下拉效果
- 很好玩的滚动效果
- 一个很好的反转效果
- div效果很好的遮盖层效果
- div效果很好的遮盖层效果
- div效果很好的遮盖层效果
- div效果很好的遮盖层效果
- 一个很好的效果,隐藏表格
- 一个很好的相册切换效果
- 动态时间显示效果,很好看哦
- 一个很好的相册浏览效果
- 老中医点评各种水果效果很好
- matlab实现gabor filter (8) 效果很好
- matlab实现gabor filter (9) 效果很好
- matlab实现gabor filter (10) 效果很好
- Hadoop2.7.1 集群安装指南
- SSH 不可以远程调试QEMU
- 数据类型的隐性转型和显性转型
- 黑马程序员——Java基础---集合框架
- C++STL学习(4)容器set和multiset
- GoogleCardsActivity 效果很好
- 黑马程序员--反射
- Java内省
- 版本管理--MyEclipse使用svn插件管理项目
- 带左标题的文本框UITextField,并实现return键回收键盘效果--iOS 开发
- Scala练习题01:找出列表中最后一个元素
- 《平凡的世界》有感
- iOS程序性能优化(一)
- 一次加密通信和SSL通信,openssl自建CA