BaseAdapter应用 和gallery滑动图片
来源:互联网 发布:丸子网络传世论坛 编辑:程序博客网 时间:2024/05/23 11:50
public class MyActivity extends Activity {
//定变量
private Gallery gallery;
private MyGalleryBase myGalleryBase;
private Gallery gallery;
private MyGalleryBase myGalleryBase;
//创建int类型的图片数组,将图片都添加进去
private int[] mImage=new int[]{R.drawable.chitong,R.drawable.proxy,R.drawable.quanyuan,R.drawable.thumb,R.drawable.tong};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
private int[] mImage=new int[]{R.drawable.chitong,R.drawable.proxy,R.drawable.quanyuan,R.drawable.thumb,R.drawable.tong};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//找到Gallery的id
gallery=(Gallery)findViewById(R.id.onegallery);
gallery=(Gallery)findViewById(R.id.onegallery);
//初始化自定义适配器,并且将图片添加入这个适配器
myGalleryBase=new MyGalleryBase(mImage,this);
myGalleryBase=new MyGalleryBase(mImage,this);
//将gallera改为这个适配器的数据
gallery.setAdapter(myGalleryBase);
}
}
gallery.setAdapter(myGalleryBase);
}
}
//创建自定义适配器
public class MyGalleryBase extends BaseAdapter {
//需要图片就创建图片的数组,图片数组为int
private int[] mImage;
private int[] mImage;
//引用上下文
private Context mContext;
private Context mContext;
//讲XML转成view对象
private LayoutInflater mlayoutInflater;
private LayoutInflater mlayoutInflater;
//构造方法
public MyGalleryBase(int[] images,Context context){
public MyGalleryBase(int[] images,Context context){
//初始化
mImage=images;
mContext=context;
mlayoutInflater=LayoutInflater.from(context);
}
mImage=images;
mContext=context;
mlayoutInflater=LayoutInflater.from(context);
}
//显示条目数量
@Override
public int getCount() {
@Override
public int getCount() {
//显示多少次
return mImage.length;
}
//
@Override
public Object getItem(int position) {
return mImage.length;
}
//
@Override
public Object getItem(int position) {
//返回数据
return mImage[position];
}
@Override
public long getItemId(int position) {
return mImage[position];
}
@Override
public long getItemId(int position) {
//返回下标
return position;
}
@Override
return position;
}
@Override
//int position 下标 View convertView 布局的对象 ViewGroup parent父类对象
public View getView(int position, View convertView, ViewGroup parent) {
public View getView(int position, View convertView, ViewGroup parent) {
//View v可以不用定义 使用View convertView 都代表布局对象
View v=mlayoutInflater.inflate(R.layout.view_gallery,null);
ImageView imageView=(ImageView)v.findViewById(R.id.oneimageview);
ImageView imageView=(ImageView)v.findViewById(R.id.oneimageview);
//导入图片为这个位置
imageView.setImageResource(mImage[position]);
return v;
}
}
imageView.setImageResource(mImage[position]);
return v;
}
}
//创建Gallery xml
<Gallery
android:id="@+id/onegallery"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/onegallery"
android:layout_width="match_parent"
android:layout_height="match_parent"
//中间的间距
android:spacing="10dp">
</Gallery>
android:spacing="10dp">
</Gallery>
//创建判断 地址 实现复用
//布局id
private int layoutid;
//存放内容id
private int nrviewlauid;
public MyGalleryBase(int[] images,Context context,int layoutid,int nrviewlauid){
mImage=images;
mContext=context;
mlayoutInflater=LayoutInflater.from(context);
this.layoutid=layoutid;
this.nrviewlauid=nrviewlauid;
}
private int nrviewlauid;
public MyGalleryBase(int[] images,Context context,int layoutid,int nrviewlauid){
mImage=images;
mContext=context;
mlayoutInflater=LayoutInflater.from(context);
this.layoutid=layoutid;
this.nrviewlauid=nrviewlauid;
}
public View getView(int position, View convertView, ViewGroup parent) {
//用v来接收内容id nrviewlauid为可变的id
View v=mlayoutInflater.inflate(nrviewlauid,null);
View v=mlayoutInflater.inflate(nrviewlauid,null);
//用v1来接受布局id
View v1= v.findViewById(layoutid);
//判断布局的id是否继承与ImageView
if(v1 instanceof ImageView){
if(v1 instanceof ImageView){
//将内容存入
((ImageView) v1).setImageResource(mImage[position]);
}
return v;
}
((ImageView) v1).setImageResource(mImage[position]);
}
return v;
}
0 0
- BaseAdapter应用 和gallery滑动图片
- Gallery和BaseAdapter容器
- 用Gallery和ImageView实现图片滑动
- android Gallery滑动图片
- Android深入浅出系列之实例应用—简单的手指拖动图片,图片滑来滑去显示应用Gallery和BaseAdapter以及ImageView的使用
- Android深入浅出系列之实例应用—简单的手指拖动图片,图片滑来滑去显示应用Gallery和BaseAdapter以及ImageView的使用
- 6.3 Gallery和BaseAdapter容器
- android 拖拉图片 Gallery 用BaseAdapter实现
- Android Gallery图片一张张滑动
- 使用Gallery滑动查看图片
- Android Gallery图片一张张滑动
- gallery一次滑动一张图片
- Gallery实现横向滑动图片
- BaseAdapter + Gallery
- Gallery与衍生BaseAdapter容器创建图片预览详解
- Android gallery+BaseAdapter实现简易的图片查看器
- android Gallery 仿iPhone 图片滑动
- android Gallery 仿iPhone 图片滑动
- Exception in thread \"main\" java.lang.OutOfMemoryError: Java heap space .
- weblogic安装时出现Eclipse安装主目录无效
- highcharts设置背景颜色,设置数据点单位,加大字体等
- netcdf放在weblogic下与spring-modules.jar冲突问题的解决
- java压缩文件夹
- BaseAdapter应用 和gallery滑动图片
- python在windows里面输入文件路径的转义符问题
- java向Excel固定单元格写入值
- 【转载】Maven使用入门
- 【转载】Maven简介
- 【转载】Maven的安装和配置
- 【转载】互联网创业的七个必要条件
- 【转载】Maven实战(八)——常用Maven插件介绍(下)
- JavaWeb中记录访问终端的方法