Gridview: how to fill all the space with a text view

I create a calendar using GridView(6 rows * 8 columns). Each of the cells inside this matrix (6 * 8) is TextView(which I dynamically create in my program).

The problem I am facing is that the 6 * 8 matrix does not fill all the space available for the GridView

I would like the 6 * 8 matrix to occupy the entire space in GridView, rather than leave the empty space b / w matrix and the next TextView. Can anyone help me on this.

Below is the xml layout GridView

<?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"
android:layout_weight="1" >

    <GridView xmlns:android="http://schemas.android.com/apk/res/android" 
        android:id="@+id/gridview"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:numColumns="8"
        android:verticalSpacing="10dp"
        android:horizontalSpacing="10dp"
        android:gravity="center"
        android:layout_weight="1"
            />


    <TextView  
            android:id="@+id/id_worked"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="Result 1 ->"
        android:layout_weight="0"
        android:textSize="20sp"
        />
</LinearLayout>

Grid view

+5
source share
1 answer

Remove

    android:verticalSpacing="10dp"
    android:horizontalSpacing="10dp"

from the GridView element. This reduces the interval.

: LinearLayout .

<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_weight="1"
android:weightSum="6">
    <LinearLayout android:layout_width="fill_parent"
         android:layout_height="fill_parent" android:layout_weight="1">items here</LinearLayout>
    <LinearLayout android:layout_width="fill_parent"
         android:layout_height="fill_parent" android:layout_weight="1">items here</LinearLayout>
    <LinearLayout android:layout_width="fill_parent"
         android:layout_height="fill_parent" android:layout_weight="1">items here</LinearLayout>
    <LinearLayout android:layout_width="fill_parent"
         android:layout_height="fill_parent" android:layout_weight="1">items here</LinearLayout>
    <LinearLayout android:layout_width="fill_parent"
         android:layout_height="fill_parent" android:layout_weight="1">items here</LinearLayout>
    <LinearLayout android:layout_width="fill_parent"
         android:layout_height="fill_parent" android:layout_weight="1">items here</LinearLayout>
</LinearLayout>
+1

All Articles