Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Reduce space between columns in GridView

See attached screenshot where I am attempting to reduce the space between the columns in my GridView.

My main.xml is as follows:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<GridView 
android:id="@+id/gridview"
android:layout_width="wrap_content" 
android:layout_height="wrap_content"
android:stretchMode="columnWidth"
android:gravity="center"
/>
<LinearLayout 
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
    <ImageView 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/logo"/>
    <TextView
    android:text="@string/game_score"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:layout_gravity="center"/>
</LinearLayout>
</LinearLayout>

I am creating the ImageViews in my code from a Bitmap. However, I am not specifying any padding or spacing or otherwise.

How can I reduce this space between columns? I've tried a variety of settings on both GridViews and ImageViews but with no luck

Image is here:

Thanks

like image 983
DJ180 Avatar asked Sep 15 '11 03:09

DJ180


Video Answer


2 Answers

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"
like image 116
deepa Avatar answered Oct 08 '22 16:10

deepa


Remove Gravity attribute and use the following mode

android:stretchMode="NONE"
like image 45
sravan Avatar answered Oct 08 '22 16:10

sravan