package
com.example.gallery;
import
android.content.Context;
import
android.view.View;
import
android.view.ViewGroup;
import
android.widget.BaseAdapter;
import
android.widget.Gallery;
import
android.widget.ImageView;
public
class
GalleryAdapter
extends
BaseAdapter {
private
Context mContext;
int
[] images = {R.mipmap.apple, R.mipmap.banana, R.mipmap.bicycle, R.mipmap.chair,R.mipmap.chopsticks, R.mipmap.dog, R.mipmap.fish, R.mipmap.pear};
public
GalleryAdapter (Context context) {
this
.mCOntext= context;
}
@Override
public
int
getCount() {
return
images.length;
}
@Override
public
Object getItem(
int
i) {
return
i;
}
@Override
public
long
getItemId(
int
i) {
return
i;
}
@Override
public
View getView(
int
i, View view, ViewGroup viewGroup) {
ImageView image =
new
ImageView(mContext);
image.setImageResource(images[i]);
image.setAdjustViewBounds(
true
);
image.setLayoutParams(
new
Gallery.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
return
image;
}
}