列表视图背景在Droid 3上是灰色的

时间:2011-08-30 15:45:15

标签: android listview background

我有一个带有自定义背景的列表框。它在两侧显示一条带有黑色背景的细白线。适用于我所有的测试手机(Galaxy Captivate,Vibrant,Nexus 1,G Tablet,Archos 32,Droid)。我刚刚有一个Droid 3进行测试,在这一款手机上,listview的背景中没有任何项目是灰色的。列表项具有正确的黑色背景。

这是包含列表视图的布局。列表视图上方和下方都有白色背景文本框,列表视图的背景是可绘制的(我知道它叫做三个边框,但它只有两个边框)。

<RelativeLayout
    android:layout_below="@id/divider01"
    android:layout_above="@id/save_current_button"
    android:id="@+id/profile_middle_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="3dip"
    android:orientation="vertical">
    <TextView  android:id="@+id/user_profile_row"
        android:text="@string/user_profiles_label"
        android:layout_alignParentTop="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:textColor="@android:color/black"
        android:background="@drawable/roundedtop"/>
    <TextView android:id="@+id/current_profile_name"
        android:layout_alignParentBottom="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:textColor="#2B497B"
        android:background="@drawable/roundedbottom"/>
    <ListView android:id="@id/android:list"
        android:layout_below="@id/user_profile_row"
        android:layout_above="@id/current_profile_name"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:paddingLeft="3dip"
        android:paddingRight="3dip"
        android:drawSelectorOnTop="false"
        android:background="@drawable/three_side_border"
        android:cacheColorHint="#ffffffff"/>
</RelativeLayout>

这是可绘制的 - 这应该强制背景为黑色。

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#FFFFFFFF" />
        </shape>
    </item>

    <item android:left="3dp" android:right="3dp"> 
        <shape android:shape="rectangle">
            <solid android:color="#FF000000" />
        </shape>
    </item>
</layer-list>

我注意到在我的列表项xml中,我没有在我的颜色中指定alpha层,所以我尝试在我的drawable上取下前导FF,但它出现了相同。

任何人都有任何想法我可以解决这个问题吗?在一部漂亮的手机上看起来真的很难看。

谢谢, 格雷格

1 个答案:

答案 0 :(得分:24)

一位好友在摩托罗拉论坛上发表评论:

  

摩托罗拉在Moto设备上更改了内置主题的属性值   用2.3。 “如果您将overScrollFooter设置为@null,则列表底部   背景变得透明,您的背景图像显示   通过....如果你想要一个列表底部的背景,但不同   一,你可以将overScrollFooter设置为颜色或可绘制的......“

android:overScrollFooter="#aa000000"
android:overScrollFooter="@drawable/my_drawable"

http://community.developer.motorola.com/t5/MOTODEV-Blog/Why-Does-My-ListView-Look-Different/ba-p/17462

在渲染这个空间时,我仍然不完全确定他们在做什么,但我可以让它工作。如果我使用drawable选项,并使用左边框和右边框将其绘制为drawable,那么该对象将从listview背景中绘制到边框内 - 即它仍以某种方式显示我的双层背景中的第一个项目drawable,因此我的列表项下面的空间现在有一个更宽的边框,但它是黑色的。这至少与我之前的测试一致,当我将第一层更改为蓝色,并在列表视图的整个高度上得到一条蓝线。如果我只选择直的黑色#ff000000,那么listview看起来和我所有的其他手机一样。所以我不确定他们是如何计算页脚空间的 - 我不知道他们怎么知道我有一个双层对象而只是替换第二层。还有其他事情必须继续,我只是不明白,但确实有效。

还有一条评论说您需要根据Android版本选择一个主题,但到目前为止,在我的测试中,所有平台都采用了新标签而没有抱怨。