Guest User

Untitled

a guest
Feb 18th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.50 KB | None | 0 0
  1. package dario.magic;
  2.  
  3. import android.content.Context;
  4. import android.content.res.TypedArray;
  5. import android.view.View;
  6. import android.view.ViewGroup;
  7. import android.widget.BaseAdapter;
  8. import android.widget.Gallery;
  9. import android.widget.ImageView;
  10.  
  11. public class ImageAdapter extends BaseAdapter
  12. {
  13.     int mGalleryItemBackground;
  14.     private Context mContext;
  15.  
  16.     private Integer[] mImageIds =
  17.     {
  18.             R.drawable.planks_1,
  19.             R.drawable.planks_2,
  20.             R.drawable.planks_3,
  21.             R.drawable.planks_4,
  22.             R.drawable.planks_5,
  23.             R.drawable.planks_6,
  24.             R.drawable.planks_7,
  25.     };
  26.  
  27.     public ImageAdapter(Context c)
  28.     {
  29.         mContext = c;
  30.         TypedArray a = c.obtainStyledAttributes(R.styleable.BG_Gallery);
  31.         mGalleryItemBackground = a.getResourceId(
  32.                 R.styleable.BG_Gallery_android_galleryItemBackground, 0);
  33.         a.recycle();
  34.     }
  35.  
  36.     public int getCount()
  37.     {
  38.         return mImageIds.length;
  39.     }
  40.  
  41.     public Object getItem(int position)
  42.     {
  43.         return position;
  44.     }
  45.  
  46.     public long getItemId(int position)
  47.     {
  48.         return position;
  49.     }
  50.  
  51.     public View getView(int position, View convertView, ViewGroup parent)
  52.     {
  53.         ImageView i = new ImageView(mContext);
  54.  
  55.         i.setImageResource(mImageIds[position]);
  56.         i.setLayoutParams(new Gallery.LayoutParams(200, 200));
  57.         i.setScaleType(ImageView.ScaleType.FIT_XY);
  58.         i.setBackgroundResource(mGalleryItemBackground);
  59.  
  60.         return i;
  61.     }
  62. }
Add Comment
Please, Sign In to add comment