基本信息
源码名称:android 图片浏览器
源码大小:4.05M
文件格式:.rar
开发语言:Java
更新时间:2015-09-08
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
package com.example.zuoye1;
import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.SpinnerAdapter;
import android.widget.ViewSwitcher.ViewFactory;
import com.example.zuoye1.R;
public class MainActivity extends Activity implements ViewFactory,
OnItemClickListener {
private ImageSwitcher imageSwitcher;
private Gallery gallery;
// 存放大图的数组
private int[] imagesLarge = { R.drawable.img1, R.drawable.img2,
R.drawable.img3, R.drawable.img4, R.drawable.img5 };
// 存放小图的数组
private int[] imagesSmall = { R.drawable.img1, R.drawable.img2,
R.drawable.img3, R.drawable.img4, R.drawable.img5 };
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 设置窗体无标题
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
// 得到组件
imageSwitcher = (ImageSwitcher) this.findViewById(R.id.imageSwitcher1);
imageSwitcher.setFactory(this);
imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,
android.R.anim.fade_in));
imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,
android.R.anim.fade_out));
gallery = (Gallery) this.findViewById(R.id.gallery1);
gallery.setAdapter(new ImageAdapter());
// 设置默认选择的图片
gallery.setSelection(imagesSmall.length / 2);
// 注册事件监听器
gallery.setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView<?> adapterview, View view, int postion,
long id) {
imageSwitcher.setImageResource(imagesLarge[postion]);
}
// 重写视图工厂中的makeView方法,对ImageSwitcher显示的ImageView对象进行了设置
@Override
public View makeView() {
ImageView imageView = new ImageView(MainActivity.this);
imageView.setLayoutParams(new ImageSwitcher.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
return imageView;
}
/**
* 负责产生gallery中的图片
*/
private class ImageAdapter extends BaseAdapter implements SpinnerAdapter {
// 返回图片的个数,比如你想得到图片的个数
@Override
public int getCount() {
return imagesSmall.length;
}
@Override
public Object getItem(int position) {
return imagesSmall[position];
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = new ImageView(MainActivity.this);
// 设置imageView中的图像资源
imageView.setImageResource(imagesSmall[position]);
// 设置图像大小尺寸自适应
imageView.setAdjustViewBounds(true);
return imageView;
}
}
}