Gridview:如何使用文本视图填充整个空间

Raj*_*Raj 5 layout android gridview

我正在使用GridView(6行*8列)创建日历.这个矩阵(6*8)中的每个单元格都是TextView(我在程序中动态创建).

我面临的问题是,6*8矩阵没有填充GridView可用的整个空间

我想让6*8矩阵占据整个空间,GridView而不是留下一些空白区域,而不是矩阵和下一个TextView.有人可以帮我这个.

下面给出的是xml布局 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>
Run Code Online (Sandbox Code Playgroud)

网格视图

Ron*_*nie 1

去除

    android:verticalSpacing="10dp"
    android:horizontalSpacing="10dp"
Run Code Online (Sandbox Code Playgroud)

来自 GridView 元素。这应该减少间距。

编辑:使用 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>
Run Code Online (Sandbox Code Playgroud)