I want to place an 8x8 grid of images, actually only 40x40px icons, in a GridView layout using the ImageView class.
I tried to play with the setLayoutParams and setScaleType methods of the ImageView class, but could not achieve the desired effect. Here's what I have, but I'm only experimenting with a 3x3 grid of small icons until I get it.
The main utility:
package com.topherwilso.ropasci; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.widget.GridView; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); GridView gv = (GridView) findViewById(R.id.gridview); gv.setAdapter(new ImageAdapter(getApplicationContext())); } @Override public boolean onCreateOptionsMenu(Menu menu) {
And my ImageAdapter class:
package com.topherwilso.ropasci; import android.content.Context; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.GridView; import android.widget.ImageView; import android.widget.ImageView.ScaleType; public class ImageAdapter extends BaseAdapter { int[] images = { R.drawable.one, R.drawable.two, R.drawable.three, R.drawable.four, R.drawable.five, R.drawable.six, R.drawable.seven, R.drawable.eight, R.drawable.nine }; private Context context; public ImageAdapter(Context applicationContext){ context=applicationContext; } @Override public int getCount() {
Here's what it looks like now

This is what I would like

source share