Sanjana Nair
Sanjana Nair

Reputation: 2785

GridView items not showing up fully in Android

All GridView Items aren't showing up until I give the height for the layout.

The same settings in a differnt xml works fine.

How will I make it to show all items without giving the height.

It always shows only two items.

Please see below what i had done :

 <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/gridOptionsView"
                android:layout_marginBottom="10dp"
                android:visibility="gone"
                android:orientation="vertical" >

                <GridView
                    android:id="@+id/OptionsGrid"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:columnWidth="125dp"
                    android:horizontalSpacing="5dp"
                    android:layout_marginBottom="5dp"
                    android:scrollbars="vertical"
                    android:verticalSpacing="5dp"
                    android:numColumns="2"
                    android:visibility="visible">
                </GridView>

            </LinearLayout>

I have different Linearlayouts in the XML one of them is shown above.

I am not able to track the issue.

Thanks!

Upvotes: 1

Views: 6278

Answers (3)

HourGlass
HourGlass

Reputation: 1830

Your LinearLayout is the parent layout.

<LinearLayout>
    android:layout_height="wrap_content"
</LinearLayout>

when you set your GridView height to match_parent.

The parent layout here is LinearLayout and its layout_height is wrap_content. So your GridView will not be displayed in full display height.

Do this instead.

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/gridOptionsView"
    android:layout_marginBottom="10dp"
    android:visibility="gone"
    android:orientation="vertical" >

    <GridView
        android:id="@+id/OptionsGrid"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:columnWidth="125dp"
        android:horizontalSpacing="5dp"
        android:layout_marginBottom="5dp"
        android:scrollbars="vertical"
        android:verticalSpacing="5dp"
        android:numColumns="2"
        android:visibility="visible">
    </GridView>
</LinearLayout>

Upvotes: 1

Pravin Fofariya
Pravin Fofariya

Reputation: 346

Try this

Your source code LinearLayout is the main container layout so this layout change this statement

android:layout_height="wrap_content" to android:layout_height="match_parent"

so but when you set your gridview height to match_parent. The parent layout Layout_height is wrap_content. So that reason your gridview will not be display in full display. change done in below code

 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/gridOptionsView"
    android:layout_marginBottom="10dp"
    android:visibility="gone"
    android:orientation="vertical" >

    <GridView
        android:id="@+id/OptionsGrid"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:columnWidth="125dp"
        android:horizontalSpacing="5dp"
        android:layout_marginBottom="5dp"
        android:scrollbars="vertical"
        android:verticalSpacing="5dp"
        android:numColumns="2"
        android:visibility="visible">
    </GridView>
</LinearLayout>

Upvotes: 3

Jas
Jas

Reputation: 3212

Change your GridView height from

android:layout_height="match_parent"

to

android:layout_height="wrap_content"

Upvotes: 0

Related Questions