2013-02-06 55 views
4

我需要的GridView没有填充在Android的API小于10.我的布局:GridView的填充小于10

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
tools:context=".MainActivity" > 

<GridView 
    android:id="@+id/grid" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentTop="true" 
    android:alwaysDrawnWithCache="true" 
    android:background="@color/gridview_background" 
    android:clipChildren="true" 
    android:horizontalSpacing="1dp" 
    android:numColumns="6" 
    android:verticalSpacing="1dp" /> 

结果:

enter image description here

红色箭头在填充上显示。这只是在Android的< 3.0的结果,我需要

enter image description here

没有填充。

P.S.完全相同的android 3.0上的代码没有填充。这是为什么?

+0

哪个是你的目标SDK,哪个是你的minSDK? – JoeHz

+0

我的minSdkVersion是8,targetSdkVersion是16. – Viacheslav

回答

5

我几乎找不到答案=)。在2.x风格的Android上是你的listSelector,而它的4.x.在4.x上,他可能是空的,而且2.x比这个更大,并且在吠叫时填入他需要放置的属性:

android: listSelector="@null" 
+0

你先生是天才!你怎么解决这个问题? – CaseyB

+0

直觉帮了我。 =) – Viacheslav

+1

我使用https://github.com/TonicArtos/StickyGridHeaders中的“StickyGridHeaders”,并且在添加填充时,网格中的所有内容都变得疯狂(白色插槽,负面滚动等)。添加此属性后它完美无瑕! – Gero

0

我会建议在4.x SDK下编译以获得您想要的行为,但包括您想要在您的minSDK中支持的设备。

我会不是建议使用级别10/Android 3.0作为Honeycomb是Android的平板电脑唯一的化身。您可能需要定位API级别14并且具有8-10的minSDK版本。

+0

我的minSdkVersion是8,targetSdkVersion是16 – Viacheslav

+0

你可以在编译它为16后测试它为8吗?我的诅咒是肯定的,它会按你的意愿工作 – JoeHz