Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <GridView xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:id="@+id/AppsOverviewGrid"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:columnWidth="120dp"
- android:numColumns="auto_fit"
- android:verticalSpacing="0dp"
- android:horizontalSpacing="8dp"
- android:stretchMode="columnWidth"
- android:gravity="center">
- </GridView>
- public class ImageAdapter extends BaseAdapter {
- // create a new ImageView for each item referenced by the Adapter
- public View getView(int position, View convertView, ViewGroup parent) {
- ImageView imageView;
- if (convertView == null) {
- // if it's not recycled, initialize some attributes
- imageView = new ImageView(mContext);
- imageView.setLayoutParams(new GridView.LayoutParams(120, 58));
- imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
- imageView.setPadding(8, 8, 8, 8);
- } else {
- imageView = (ImageView) convertView;
- }
- imageView.setImageResource(pictureArray[position]);
- return imageView;
- }
- // references to our images
- private Integer[] pictureArray= {
- R.drawable.pic1, R.drawable.pic2,
- }
- }
- GridView gridview = (GridView) findViewById(R.id.gridview);
- gridview.setAdapter(new ImageAdapter(this));
Add Comment
Please, Sign In to add comment