Guest User

Untitled

a guest
Oct 19th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. <GridView xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:tools="http://schemas.android.com/tools"
  3. android:id="@+id/AppsOverviewGrid"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent"
  6. android:columnWidth="120dp"
  7. android:numColumns="auto_fit"
  8. android:verticalSpacing="0dp"
  9. android:horizontalSpacing="8dp"
  10. android:stretchMode="columnWidth"
  11. android:gravity="center">
  12. </GridView>
  13.  
  14. public class ImageAdapter extends BaseAdapter {
  15.  
  16. // create a new ImageView for each item referenced by the Adapter
  17. public View getView(int position, View convertView, ViewGroup parent) {
  18. ImageView imageView;
  19. if (convertView == null) {
  20. // if it's not recycled, initialize some attributes
  21. imageView = new ImageView(mContext);
  22. imageView.setLayoutParams(new GridView.LayoutParams(120, 58));
  23. imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
  24. imageView.setPadding(8, 8, 8, 8);
  25. } else {
  26. imageView = (ImageView) convertView;
  27. }
  28.  
  29. imageView.setImageResource(pictureArray[position]);
  30.  
  31. return imageView;
  32. }
  33.  
  34. // references to our images
  35. private Integer[] pictureArray= {
  36. R.drawable.pic1, R.drawable.pic2,
  37. }
  38.  
  39. }
  40.  
  41. GridView gridview = (GridView) findViewById(R.id.gridview);
  42. gridview.setAdapter(new ImageAdapter(this));
Add Comment
Please, Sign In to add comment