GridView项目在Android中未完全显示
在我给出布局的高度之前,所有GridView项都不会显示 在不同的xml中使用相同的设置很好 如何在不给出高度的情况下显示所有项目 它总是只显示两个项目 请看下面我所做的:GridView项目在Android中未完全显示,android,gridview,Android,Gridview,在我给出布局的高度之前,所有GridView项都不会显示 在不同的xml中使用相同的设置很好 如何在不给出高度的情况下显示所有项目 它总是只显示两个项目 请看下面我所做的: <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/gridOpt
<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>
我在XML中有不同的线性布局,其中一个如上图所示
我无法跟踪该问题
谢谢 更改您的
GridView
高度
android:layout\u height=“match\u parent”
到
android:layout\u height=“wrap\u content”
从
android:layout\u height=“match\u parent”
到
android:layout\u height=“wrap\u content”
您的线性布局是父布局
<LinearLayout>
android:layout_height="wrap_content"
</LinearLayout>
您的LinearLayout
是父布局
<LinearLayout>
android:layout_height="wrap_content"
</LinearLayout>
试试这个
源代码LinearLayout是主容器布局,因此此布局会更改此语句
android:layout\u height=“wrap\u content”到android:layout\u height=“match\u parent”
所以,当您将gridview高度设置为与父项匹配时。父布局高度为包裹内容。因此,gridview不会完全显示。在下面的代码中进行更改
<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>
试试这个
源代码LinearLayout是主容器布局,因此此布局会更改此语句
android:layout\u height=“wrap\u content”到android:layout\u height=“match\u parent”
所以,当您将gridview高度设置为与父项匹配时。父布局高度为包裹内容。因此,gridview不会完全显示。在下面的代码中进行更改
<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>
添加屏幕截图,以便每个人都能更好地理解您的问题。我不明白您想说什么,xml布局中的元素总是需要布局高度
。您的应用程序在没有设置布局高度
的情况下运行怎么可能?正如@g2o所说,您面临的问题并不清楚,布局高度绝对是必需的,请添加详细信息以解释问题better@g2o:表示设置布局高度是指硬编码高度,如100dp。如果你有多个线性布局,给他们布局权重添加屏幕截图,这样每个人都能更好地理解你的问题。我不明白你想说什么,xml布局中的元素始终需要layout\u height
。您的应用程序在没有设置layout\u height
的情况下如何运行?您面临的问题并不清楚,正如@g2o所说,layout\u height是绝对需要的,请添加详细信息以解释该问题better@g2o:表示设置布局高度是指硬编码高度,如100dp。如果有多个线性布局,请为它们指定布局权重,而不是换行内容或匹配父项尝试指定线性布局匹配父项和gridview换行内容