See attached screenshot where I am attempting to reduce the space between the columns in my GridView.
My main.xml is as follows:
Space between columns is because your gridview element is not completely occupying the column space provided by grid view.
The solution to remove space between columns is to measure the device's screen width and height and divide it by the number of columns and rows. This will give the width and height for each grid view element.
you have to assign this height and width to imageview and also scale your bitmap to match the imageview.
Code:
DisplayMetrics displayMetrics=getResources().getDisplayMetrics();
screen_width=displayMetrics.widthPixels; //width of the device screen
screen_height=displayMetrics.heightPixels; //height of device screen
int view_width=screen_width/number of columns; //width for imageview
int view_height=screen_height/number of rows; //height for imageview
Imageview myImageView=(ImageView)findViewById(R.id.my_id);
myImageView.getLayoutParams().width=view_width;
myImageView.getLayoutParams().height=view_height;
Bitmap myImage=Bitmap.createScaledBitmap(src, view_width, view_height, true);//scaling the image to match the size of image view