- 浏览: 356205 次
- 性别:
- 来自: 南京
文章分类
最新评论
-
nglxl:
点赞啊,必须点赞!!深度好文,解决了困扰我多年的疑惑。
tcp 长连接与短连接 -
cofftech:
opengl源码http://www.eyesourcecod ...
OPenGL ES 关键API小结 -
mail_j:
不是很好用,很多情况都不能处理 1、没有区分关键字的大小写2、 ...
Java解析sql语句,分析出调用到的所有表 -
a455642158:
就算监听到变成了cmwap还不行,还得监听网络连接状态Stat ...
android APN切换cmwap实现 -
xuhl1022:
看了您的android 4篇 浏览器二次开发,感触颇深,写的很 ...
Android浏览器Browser二次开发(四)浏览器中的APN切换
今天主要探究Gallery和Animation的使用。 制作一个美女图片集锦。
1. 首先需要做一个列表, 用来显示类别:
...
需要自定义个一个TitleAdapter集成BaseAdapter,
使用ViewHolder的好处就是对控件进行缓存, 以便下次取方便,提高访问效率。
2. 接下来就是对类别中的美女图片的显示了,
定义xml布局文件如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView android:id="@+id/large_image"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
/>
<TextView android:id="@+id/tip"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:text="@string/slide_tip"
android:gravity="center_vertical"
android:textColor="#dd0000"
android:layout_above="@+id/gallery"/>
<Gallery
android:id="@+id/gallery"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:gravity="center"
android:padding="5dp"
android:layout_alignParentBottom="true"
android:paddingBottom="10dp" />
<LinearLayout
android:id="@+id/miniAdLinearLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
/>
</RelativeLayout>
类代码如下:
中间大图片的显示加上动画,
动画文件如下
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="0.1"
android:toAlpha="1.0"
android:duration="1500"/>
</set>
放在res/anim下。
实际效果请运行附件。
至此可完成。
1. 首先需要做一个列表, 用来显示类别:
public class CategoryActivity extends Activity implements OnItemClickListener{ private ListView mList; LayoutInflater mInflater; private Integer[] title = { R.string.jingxuan, R.string.mingxing, R.string.xinggan, R.string.cosplay, R.string.socks, R.string.more }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.category_list); mList = (ListView) findViewById(R.id.category_list); long time = System.currentTimeMillis(); if (time%3==0) { mList.setBackgroundResource(R.drawable.longze2); } else if (time%3==1){ mList.setBackgroundResource(R.drawable.pic02); } else { mList.setBackgroundResource(R.drawable.pic05); } mInflater = LayoutInflater.from(this); mList.setAdapter(new TitleAdapter(this)); mList.setOnItemClickListener(this); }
...
需要自定义个一个TitleAdapter集成BaseAdapter,
private class TitleAdapter extends BaseAdapter { private Context mContext; public TitleAdapter(Context context) { mContext = context; } @Override public int getCount() { // TODO Auto-generated method stub return title.length; } @Override public Object getItem(int arg0) { // TODO Auto-generated method stub return title[arg0]; } @Override public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder vh = null; if (convertView == null) { convertView = mInflater.inflate(R.layout.category_item, null); vh = new ViewHolder(); vh.titleView = (TextView) convertView.findViewById(R.id.cate_title); //hilight the last 'more' title if (position == title.length -1) { vh.titleView.setTextColor(CategoryActivity.this.getResources().getColor(R.color.red)); } convertView.setTag(vh); } else { vh = (ViewHolder) convertView.getTag(); } //set image resource vh.titleView.setText(title[position]); return convertView; } /** * holder for caching UI component * @author hp * */ class ViewHolder { public TextView titleView; } }
使用ViewHolder的好处就是对控件进行缓存, 以便下次取方便,提高访问效率。
2. 接下来就是对类别中的美女图片的显示了,
定义xml布局文件如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView android:id="@+id/large_image"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
/>
<TextView android:id="@+id/tip"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:text="@string/slide_tip"
android:gravity="center_vertical"
android:textColor="#dd0000"
android:layout_above="@+id/gallery"/>
<Gallery
android:id="@+id/gallery"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:gravity="center"
android:padding="5dp"
android:layout_alignParentBottom="true"
android:paddingBottom="10dp" />
<LinearLayout
android:id="@+id/miniAdLinearLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
/>
</RelativeLayout>
类代码如下:
public class ViewActivity extends Activity implements OnItemSelectedListener { private Gallery mGallery; private ImageAdapter mAdapter; LayoutInflater mInflater; private ImageView largeView; private Animation mAnimation; private int categoryId; private String imgDir = ""; private Bitmap[] imageUri; private int showCount = 0; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); this.setTitle(getIntent().getIntExtra(Constants.KEY_TITLE, R.string.app_name)); mGallery = (Gallery) findViewById(R.id.gallery); mInflater = LayoutInflater.from(this); mAdapter = new ImageAdapter(this); largeView = (ImageView) findViewById(R.id.large_image); largeView.setScaleType(ImageView.ScaleType.FIT_XY); mAnimation = AnimationUtils.loadAnimation(this, R.anim.alpha_ani); largeView.startAnimation(mAnimation); } public void onResume() { super.onResume(); showCount++; if (getIntent().getBooleanExtra(Constants.KEY_AD, false)) { if (showCount == 1) { AppConnect.getInstance(this).showOffers(this); } } else { //build from asset initFromIntent(); mGallery.setAdapter(mAdapter); mGallery.setOnItemSelectedListener(this); } } private void initFromIntent() { //set title Intent intent = getIntent(); categoryId = getIntent().getIntExtra(Constants.KEY_CATEGORY, 0); String basePath = "images/"; switch (categoryId) { //suggest hot images case 0: imgDir = "jingxuantuijian"; break; //super starts case 1: imgDir = "mingxing"; break; //sexy girls case 2: imgDir = "xinggan"; break; //cosplay case 3: imgDir = "cosplay"; break; case 4: imgDir = "socks"; break; default: imgDir = "xinggan"; break; } try { basePath += imgDir; AssetManager am = this.getAssets(); String[] files = am.list(basePath); imageUri = new Bitmap[files.length]; basePath += "/"; for(int i = 0; i < files.length; i++) { imageUri[i] = BitmapFactory.decodeStream(am.open(basePath + files[i])); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } private class ImageAdapter extends BaseAdapter { private Context mContext; public ImageAdapter(Context context) { mContext = context; } @Override public int getCount() { // TODO Auto-generated method stub return imageUri.length; } @Override public Object getItem(int arg0) { // TODO Auto-generated method stub return imageUri[arg0]; } @Override public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder vh = null; if (convertView == null) { convertView = mInflater.inflate(R.layout.item, null); vh = new ViewHolder(); vh.imgV = (ImageView) convertView.findViewById(R.id.imageV); vh.imgV.setScaleType(ImageView.ScaleType.FIT_XY); convertView.setTag(vh); } else { vh = (ViewHolder) convertView.getTag(); } //set image resource vh.imgV.setImageBitmap(imageUri[position]); return convertView; } /** * holder for caching UI component * @author hp * */ class ViewHolder { public ImageView imgV; } } @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long arg3) { //recyle old bitmap BitmapDrawable drawable = (BitmapDrawable) largeView.getDrawable(); if (drawable != null && !drawable.getBitmap().isRecycled()) { drawable.getBitmap().recycle(); } largeView.setImageBitmap(imageUri[position]); largeView.startAnimation(mAnimation); } @Override public void onNothingSelected(AdapterView<?> arg0) { } }
中间大图片的显示加上动画,
动画文件如下
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="0.1"
android:toAlpha="1.0"
android:duration="1500"/>
</set>
放在res/anim下。
实际效果请运行附件。
至此可完成。
- BG2.zip (9 MB)
- 下载次数: 238
- BeautifulGirl.rar (8.1 MB)
- 下载次数: 236
发表评论
-
基于Java NIO的手机答题游戏开发
2014-03-31 17:59 1705先上个游戏截图: 豌豆荚地址: http://apps.w ... -
enable android deviceconnection under linux
2013-04-24 15:45 962开发环境搭建完毕,Eclipse,Java,ADT都已经折腾 ... -
set CCache for building android source code
2013-04-24 15:14 1151Setting up ccache You can opti ... -
android 源码下载403 forbidden, 406 not acceptable 错误
2013-04-24 08:46 2412解决方法 1. 浏览器登录https://android.g ... -
ubuntu11.10 编译android4.0 错处
2013-04-08 21:45 1188今天使用ubuntu11.10编译android4.0出现以下 ... -
常用WebService列表
2013-01-31 23:22 2602快递查询接口 http://webservice.36wu.c ... -
startActivityForResult 无响应问题
2013-01-24 13:57 3718今天开发遇到了个问题, 就是从一个Activity中使用sta ... -
Android中仿新浪微博刷新列表
2012-11-22 17:35 7314大家看到新浪微博中的列表往下拉的时候, 头部出现正在刷新,然后 ... -
Grid调整间距
2012-09-29 08:52 1685今天使用GridView, 发现点中某一Item时选中部分的背 ... -
Android执行 shell command
2012-03-24 17:00 7213Android执行shell命令 一、方法 1. /* ... -
BBBBBB111
2012-03-23 11:42 10陈波: 本周:代码review,解决findbugs中bug以 ... -
MonkeyTestError
2012-03-21 10:15 903-20 21:36:42.439 W/dalvikvm( ... -
INSTALL_FAILED_OLDER_SDK ERROR
2012-03-12 15:52 4391Install APK with adb: $ platfo ... -
4.0源码编译问题
2012-03-07 17:12 31191、fatal error: GL/glx.h: No suc ... -
4.0 编译apk中无classes.dex
2012-03-07 17:11 3898下载完android 4.0代码,模拟器里面的gallery不 ... -
Android 4.0源码编译错误
2012-03-05 10:19 2540UNEXPECTED TOP-LEVEL EXCEPTION: ... -
AndroidLockScreenDemo
2012-02-18 15:54 925锁屏解锁的成功案例。 -
G14 root权限获取
2012-02-13 23:36 2821HTC G14 ROOT权限获取后就能删除系统自带的程序,相信 ... -
锁屏d ds
2011-12-15 00:49 838private final IDevicePolicyMana ... -
HuHug
2011-11-14 00:30 904gfjijgsdklgkg
相关推荐
Android 自定义ListView + Gallery 组合
android开发中,Gallery控件的使用,详细可以参见博客:http://www.cnblogs.com/plokmju/p/android_Gallery.html
Android Gallery 自定义ImageView和Gallery实现图片浏览功能,类似Android图库软件,主要实现的功能有:图片左右滑动、放大缩小、放大弹回、缩小弹回。 一开始使用Viewpager实现图片浏览,发现两张图片滑动时没有...
android gallery简单应用,里面有对gallery源码例子
android gallery例子android gallery例子android gallery例子
android----gallery、iamgeswitcher组件详解,及简单实例。
android gallery demoandroid gallery demoandroid gallery demo
android Gallery + ImageSwitcher
自己写的一个Android Gallery 小例子,共享给大家顺便自己保存一下。
Android Gallery 3D效果 非常好的伪3D效果...
android 2.2 platform eclipse project source code,include more than 30 animation effect by java code and xml,slide by one item and loop gallery and dragable gridview.
Android Gallery画廊 图片展示控件 博客地址:http://blog.csdn.net/csdnyuandaimaxuexi/article/details/48809349
使用gallery实现图片滑动的同时 还实现了被选中的图片放大
Android Gallery 特效
Android Gallery 左对齐,点击禁止滑动 demo
android gallery3d效果的简单实现 有遮盖 http://blog.csdn.net/kiritor/article/details/8701025
android 4.0 Gallery源码
Android 重写Gallery实现gallery的动画切换效果
Android应用源码之Gallery2_Android