安卓:GridView的显示不正确 [英] Android: Gridview not showing correctly

查看:157
本文介绍了安卓:GridView的显示不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立一个屏幕,单柱网格180像素宽,高度重视屏幕的右侧。我现在面临的问题是,在GridView的背景描绘了整个屏幕,而不是只是180像素我在XML中指定(从而阻断在的LinearLayout指定我的背景图片)。

无论是使用重量也不重解决问题。

似乎很简单但我一直在这个酝酿了几个小时也没有用。在此先感谢您的帮助。

我layout.xml如下:

 <的LinearLayout
的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:方向=垂直
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:背景=@绘制/ main_bkgd>
< GridView控件
    机器人:layout_height =FILL_PARENT
    机器人:滚动条=无
    机器人:为numColumns =1
    机器人:columnWidth时=180像素
    机器人:verticalSpacing =6DP
    机器人:layout_width =WRAP_CONTENT
    机器人:ID =@ + ID / mainmenu_grid
    机器人:重力=右
    机器人:fadingEdge =垂直
    机器人:layout_gravity =右
    机器人:背景=#000000
    35:机器人layout_weight =>
< / GridView的>
< / LinearLayout中>


解决方案

您应该指定的android:stretchMode 属性为

 的android:stretchMode =无

GridView控件声明。

设置GridView的宽度为 190px 也将解决这个问题(与defaultSelector的利润率为5像素宽的 GridView控件,你需要一个额外10px的)。

其他:你应该使用的ListView 如果你只有一列反正...

I'm trying to build a screen with a single column grid that is 180px wide and attaches to the right side of the screen. The problem I'm facing is that the background of the gridview paints the whole screen and not just that 180px I specified in the XML (thus blocking my background pic specified in the LinearLayout).

Neither using weight nor gravity solves the problem.

Seems simple enough yet I've been toying with this for hours to no avail. Thanks in advance for your help.

My layout.xml as follows:

<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>

解决方案

You should specify the android:stretchMode attribute to be none:

android:stretchMode="none"

in your GridView declaration.

Setting the GridView's width to "190px" would also solve this problem (with the defaultSelector's margins being of 5 pixels wide for the GridView, you need an extra 10px).

Other: you should probably use a ListView if you have only one column anyway...

这篇关于安卓:GridView的显示不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆