I am new to android development and I am developing an app where the app downloads pictures from server and show them in a gridView. But some extra spaces are coming up when the
Set height and width dynamically according to the screen size. this is the best way to get perfect result.
DisplayMetrics displaymetrics = new DisplayMetrics();
((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
//if you need three fix imageview in width
int devicewidth = displaymetrics.widthPixels / 3;
//if you need 4-5-6 anything fix imageview in height
int deviceheight = displaymetrics.heightPixels / 4;
holder.image_view.getLayoutParams().width = devicewidth;
//if you need same height as width you can set devicewidth in holder.image_view.getLayoutParams().height
holder.image_view.getLayoutParams().height = deviceheight;
try this in adapter in getview hope you get better result in all device
EDIT: Or to set same height same as width you can set devicewidth in height also like below:
holder.image_view.getLayoutParams().height = devicewidth;