/
GalleryImageAdapter.java
59 lines (52 loc) · 1.64 KB
/
GalleryImageAdapter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.appkefu.appkehu_3;
import android.content.Context;
import android.content.res.TypedArray;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.Gallery.LayoutParams;
public class GalleryImageAdapter extends BaseAdapter {
private int GalleryItemBackground ;
private Context context = null ;
public int [] images ={
R.drawable.xiezi1,
R.drawable.xiezi2,
R.drawable.xiezi3,
R.drawable.xiezi4,
R.drawable.xiezi5,
R.drawable.xiezi6,
R.drawable.xiezi7,
R.drawable.xiezi8,
};
public GalleryImageAdapter(Context context){
this.context = context ;
TypedArray typedArray = context.obtainStyledAttributes(R.styleable.Gallery);
GalleryItemBackground = typedArray.getResourceId(R.styleable.Gallery_android_galleryItemBackground, 0);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return images.length;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
@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.setImageResource(images[position%images.length]);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageView.setLayoutParams(new Gallery.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
imageView.setBackgroundResource(GalleryItemBackground);
return imageView;
}
}