Android:GridView未正确显示

3
我正在尝试构建一个屏幕,其中包含一个单列网格,宽度为180像素,并连接到屏幕的右侧。我面临的问题是gridview的背景会覆盖整个屏幕,而不仅仅是我在XML中指定的那180像素(这样会阻挡LinearLayout中指定的背景图片)。
使用权重(weight)或重力(gravity)都无法解决这个问题。
看起来很简单,但我已经花了几个小时来摆弄这个问题,但仍然无济于事。提前感谢您的帮助。
我的layout.xml如下:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" 
android:background="@drawable/main_bkgd">
<GridView 
    android:layout_height="fill_parent" 
    android:scrollbars="none" 
    android:numColumns="1" 
    android:columnWidth="180px" 
    android:verticalSpacing="6dp" 
    android:layout_width="wrap_content" 
    android:id="@+id/mainmenu_grid" 
    android:gravity="right" 
    android:fadingEdge="vertical" 
    android:layout_gravity="right" 
    android:background="#000000" 
    android:layout_weight=".35">
</GridView>
</LinearLayout>
2个回答

2

您应该将android:stretchMode属性指定为none

android:stretchMode="none"

在你的GridView声明中。
将GridView的宽度设置为"190px"也可以解决这个问题(默认选择器的边距对于GridView是5像素宽,你需要额外的10px)。
另外:如果你只有一列的话,最好使用ListView...

谢谢。将宽度设置为190就可以解决问题,甚至不需要使用拉伸模式... - MikeC
2
使用stretchmode会更加简洁。 - njzk2

0

改变GridView的背景颜色         android:background =“#333” 我不知道为什么默认情况下它完全是白色的字体和背景,因此它是不可见的。 我认为这是早期版本中的一个错误。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接