package com.android.gallerydemo;
import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
public class GalleryDemo extends Activity {
private Gallery gallery;
private ImageAdapter imageAdapter;
// 声明图片的数组
private int[] resIds = {
R.drawable.item1, R.drawable.item2, R.drawable.item3, R.drawable.item4,
R.drawable.item5, R.drawable.item6, R.drawable.item7, R.drawable.item8,
R.drawable.item9, R.drawable.item10, R.drawable.item11, R.drawable.item12,
R.drawable.item13, R.drawable.item14, R.drawable.item15,
};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
gallery = (Gallery) findViewById(R.id.gallery);
imageAdapter = new ImageAdapter(this);
gallery.setAdapter(imageAdapter);
}
public class ImageAdapter extends BaseAdapter {
private Context context;
int mGralleryItemBackground; // 使用简单的计数器,主要是完成往每一个Item中去填充背景的图片
public ImageAdapter(Context context) {
this.context = context;
// 使用类型数组来读取属性
TypedArray typedArray = obtainStyledAttributes(R.styleable.Gallery);
mGralleryItemBackground = typedArray.getResourceId(
R.styleable.Gallery_android_galleryItemBackground, 0);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return Integer.MAX_VALUE; // 返回当前适配器最大值,是整数类型的。
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return resIds[position]; // 返回数组resIds[]的位置信息
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = new ImageView(context);
// 表示往imageView中填充图片的信息,填充的时候传递是resIds[]的下标
imageView.setImageResource(resIds[position % resIds.length]);
// 表示当前ImageView 把图片 不按比例扩大/缩小到View的大小显示
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
// 设置ImageView的大小
imageView.setLayoutParams(new Gallery.LayoutParams(200, 150));
// 设置ImageView的背景
imageView.setBackgroundResource(mGralleryItemBackground);
// TODO Auto-generated method stub
return imageView;
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
对应博文地址:http://blog.csdn.net/xukunhui2/article/details/9034641 Gallery控件一般是用于显示图像列表,因此也称为是画廊控件, Gallery只能水平显示一行,而且支持水平滑动效果。也就是说,单击、选中或者拖动Gallery中的图像, Gallery图像中的列表会根据不同的情况向左向右移动,直到显示到最后的一个图像为止。
资源推荐
资源详情
资源评论
收起资源包目录
GalleryDemo.rar (62个子文件)
GalleryDemo
bin
classes.dex 5KB
res
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
item7.png 47KB
item12.png 14KB
item9.png 14KB
item6.png 49KB
item5.png 48KB
item10.png 10KB
item14.png 10KB
item3.png 51KB
ic_launcher.png 4KB
item8.png 47KB
item11.png 12KB
item15.png 12KB
item4.png 49KB
item13.png 14KB
item1.png 48KB
item2.png 51KB
drawable-mdpi
ic_launcher.png 2KB
dexedLibs
GalleryDemo.apk 496KB
classes
com
android
gallerydemo
BuildConfig.class 355B
R$layout.class 409B
R$id.class 400B
R$drawable.class 863B
GalleryDemo$ImageAdapter.class 2KB
R$attr.class 355B
R.class 627B
R$styleable.class 570B
R$string.class 442B
GalleryDemo.class 1KB
resources.ap_ 490KB
AndroidManifest.xml 740B
res
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
item7.png 48KB
item12.png 20KB
item9.png 15KB
item6.png 51KB
item5.png 50KB
item10.png 13KB
item14.png 12KB
item3.png 53KB
ic_launcher.png 4KB
item8.png 49KB
item11.png 12KB
item15.png 14KB
item4.png 51KB
item13.png 16KB
item1.png 50KB
item2.png 53KB
drawable-xhdpi
values
strings.xml 180B
attrs.xml 204B
drawable-mdpi
ic_launcher.png 3KB
layout
main.xml 413B
assets
gen
com
android
gallerydemo
BuildConfig.java 165B
R.java 2KB
proguard.cfg 1KB
.settings
org.eclipse.jdt.core.prefs 177B
src
com
android
gallerydemo
GalleryDemo.java 3KB
.project 847B
.classpath 364B
project.properties 377B
AndroidManifest.xml 740B
共 62 条
- 1
AHuier
- 粉丝: 493
- 资源: 17
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 1040g0cg310ravpiu6ibg5pg00tsipsln3ju2d0g 2
- 基于Python的SAR图像去噪CNN-NLM设计源码
- redhat6升级到redhat7,过程redhat6.x-> redhat6.10->rehat7.9 主版本最高版本
- 基于Django的流程引擎设计源码
- 基于Node.js的Express框架与MySQL的后台管理系统设计源码
- 基于Java的Flink流批一体数据处理快速集成开发框架设计源码
- FirstFilterOrderCompare
- Screenshot_2024-03-28-19-17-25-020_com.ss.android.lark.jpg
- 基于Java的车辆违章信息查询系统设计源码
- wqeAFSDADWDAESD
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页