package com.ecrock.imageviewer;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.ViewSwitcher;
import android.widget.Gallery.LayoutParams;
public class ImageViewer extends Activity implements
AdapterView.OnItemSelectedListener, ViewSwitcher.ViewFactory{
private ImageSwitcher mSwitcher;
private Integer[] mThumbIds = {
R.drawable.sample_thumb_0, R.drawable.sample_thumb_1,
R.drawable.sample_thumb_2, R.drawable.sample_thumb_3,
R.drawable.sample_thumb_4, R.drawable.sample_thumb_5,
R.drawable.sample_thumb_6, R.drawable.sample_thumb_7};
private Integer[] mImageIds = {
R.drawable.sample_0, R.drawable.sample_1, R.drawable.sample_2,
R.drawable.sample_3, R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mSwitcher = (ImageSwitcher) findViewById(R.id.switcher);
mSwitcher.setFactory(this);
mSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,
android.R.anim.fade_in));
mSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,
android.R.anim.fade_out));
Gallery g = (Gallery) findViewById(R.id.gallery);
g.setAdapter(new ImageAdapter(this));
g.setOnItemSelectedListener(this);
}
/*
*
* override for ViewSwitcher.ViewFactory#makeView()
*/
public View makeView() {
ImageView i = new ImageView(this);
i.setBackgroundColor(0xFF000000);
i.setScaleType(ImageView.ScaleType.FIT_CENTER);
i.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
return i;
}
/*
* override for
* AdapterView.OnItemSelectedListener#onItemSelected()
*/
public void onItemSelected(AdapterView parent, View v, int position, long id) {
mSwitcher.setImageResource(mImageIds[position]);
}
/*
* override for AdapterView.OnItemSelectedListener#onNothingSelected()
*/
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
public class ImageAdapter extends BaseAdapter {
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(mContext);
i.setImageResource(mThumbIds[position]);
i.setAdjustViewBounds(true);
i.setLayoutParams(new Gallery.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
i.setBackgroundResource(R.drawable.picture_frame);
return i;
}
private Context mContext;
}
}
Android 图片浏览程序 ImageViewer 源码
4星 · 超过85%的资源 需积分: 9 89 浏览量
2010-03-01
18:01:15
上传
评论
收藏 429KB ZIP 举报
ecrock
- 粉丝: 1
- 资源: 10
最新资源
- J211-T1B-A-VB一款SOT23封装P-Channel场效应MOS管
- J210-VB一款SOT23封装P-Channel场效应MOS管
- J210-T1B-A-VB一款SOT23封装P-Channel场效应MOS管
- Suno V3 AI音乐生成神器,助你秒变音乐大师,suno AI音乐使用教程
- 自适应极化滤波完成P/S波分离
- 0b40adff-950d-44cf-88e6-f4a64292b638.apk
- J209-VB一款SOT23封装P-Channel场效应MOS管
- OLED12864模块(IIC接口)中文说明书.pdf
- 22304010116工管余文贤.bak
- 电路各单元电路的特点与作用
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
- 4
- 5
前往页