Android: Reduce Space Between Columns In Gridview
Solution 1:
try to fix the number of columns needed in xml file for grid and set stretchMode as columnwidth
android:numColumns="3"android:columnWidth="60dp"android:stretchMode="columnWidth"
or set the horizontal and vertical spacing in xml for grid
android:verticalSpacing="10dp"android:horizontalSpacing="10dp"
Solution 2:
Solution 3:
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 screenint view_width=screen_width/number of columns; //width for imageviewint 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
Solution 4:
Hi i had the same problem i solved by mygridView.setStretchMode(GridView.NO_STRETCH);
Solution 5:
I had the same problem. I minimized column space by doing this
for gridView
android:numColumns="2"android:columnWidth="90dp"android:verticalSpacing="0dp"android:horizontalSpacing="-30dp"android:stretchMode="columnWidth"
for imageView
android:layout_width="115dp"android:layout_height="150dp"android:padding="1dp"android:layout_marginLeft="30dp"android:layout_marginRight="-15dp"
Post a Comment for "Android: Reduce Space Between Columns In Gridview"