Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package dario.magic;
- 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;
- public class ImageAdapter extends BaseAdapter
- {
- int mGalleryItemBackground;
- private Context mContext;
- private Integer[] mImageIds =
- {
- R.drawable.planks_1,
- R.drawable.planks_2,
- R.drawable.planks_3,
- R.drawable.planks_4,
- R.drawable.planks_5,
- R.drawable.planks_6,
- R.drawable.planks_7,
- };
- public ImageAdapter(Context c)
- {
- mContext = c;
- TypedArray a = c.obtainStyledAttributes(R.styleable.BG_Gallery);
- mGalleryItemBackground = a.getResourceId(
- R.styleable.BG_Gallery_android_galleryItemBackground, 0);
- a.recycle();
- }
- public int getCount()
- {
- return mImageIds.length;
- }
- public Object getItem(int position)
- {
- return position;
- }
- public long getItemId(int position)
- {
- return position;
- }
- public View getView(int position, View convertView, ViewGroup parent)
- {
- ImageView i = new ImageView(mContext);
- i.setImageResource(mImageIds[position]);
- i.setLayoutParams(new Gallery.LayoutParams(200, 200));
- i.setScaleType(ImageView.ScaleType.FIT_XY);
- i.setBackgroundResource(mGalleryItemBackground);
- return i;
- }
- }
Add Comment
Please, Sign In to add comment