Guest User

Untitled

a guest
Sep 25th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. package test.tet;
  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. int mGalleryItemBackground;
  13. private Context mContext;
  14.  
  15. private Integer[] mImageIds = {
  16. R.drawable.sample_1,
  17. R.drawable.sample_2,
  18. R.drawable.sample_3,
  19. R.drawable.sample_4,
  20. R.drawable.sample_5,
  21. R.drawable.sample_6,
  22. R.drawable.sample_7
  23. };
  24.  
  25. public ImageAdapter(Context c) {
  26. mContext = c;
  27. TypedArray attr = mContext.obtainStyledAttributes(R.styleable.HelloGallery);
  28. mGalleryItemBackground = attr.getResourceId(
  29. R.styleable.HelloGallery_android_galleryItemBackground, 0);
  30. attr.recycle();
  31. }
  32.  
  33. public int getCount() {
  34. return mImageIds.length;
  35. }
  36.  
  37. public Object getItem(int position) {
  38. return position;
  39. }
  40.  
  41. public long getItemId(int position) {
  42. return position;
  43. }
  44.  
  45. //debug
  46. public void setLayoutParams(int x,int y){
  47.  
  48. }
  49.  
  50. public View getView(int position, View convertView, ViewGroup parent) {
  51. ImageView imageView = new ImageView(mContext);
  52.  
  53. imageView.setImageResource(mImageIds[1]);
  54. imageView.setLayoutParams(new Gallery.LayoutParams(300, 300));
  55. imageView.setScaleType(ImageView.ScaleType.FIT_XY);
  56. imageView.setBackgroundResource(mGalleryItemBackground);
  57.  
  58. return imageView;
  59. }
  60. }
Add Comment
Please, Sign In to add comment