简体   繁体   English

GridView项目无法在Android中完全显示

[英]GridView items not showing up fully in Android

All GridView Items aren't showing up until I give the height for the layout. 在我给出布局高度之前,不会显示所有GridView项目。

The same settings in a differnt xml works fine. 相同的设置在不同的xml中可以正常工作。

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. 我在XML中有不同的Linearlayouts,上面显示了其中之一。

I am not able to track the issue. 我无法跟踪该问题。

Thanks! 谢谢!

Try this 尝试这个

Your source code LinearLayout is the main container layout so this layout change this statement 您的源代码LinearLayout是主要的容器布局,因此此布局更改了此语句

android:layout_height="wrap_content" to android:layout_height="match_parent" android:layout_height =“ wrap_content”转换android:layout_height =“ match_parent”

so but when you set your gridview height to match_parent. 因此,但是当您将gridview的高度设置为match_parent时。 The parent layout Layout_height is wrap_content. 父布局Layout_height为wrap_content。 So that reason your gridview will not be display in full display. 因此,您的gridview将不会完整显示。 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>

Your LinearLayout is the parent layout. 您的LinearLayout是父布局。

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

when you set your GridView height to match_parent . 当您将GridView高度设置为match_parent

The parent layout here is LinearLayout and its layout_height is wrap_content . 此处的父布局为LinearLayout ,其layout_heightwrap_content So your GridView will not be displayed in full display height. 因此,您的GridView将不会以完整的显示高度显示。

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>

Change your GridView height from 从更改GridView高度

android:layout_height="match_parent"

to

android:layout_height="wrap_content"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM