【问题标题】:Listview background is grey on Droid 3Droid 3 上的 Listview 背景是灰色的
【发布时间】:2011-08-30 15:45:15
【问题描述】:

我有一个带有自定义背景的列表框。它在两侧显示一条带有黑色背景的细白线。在我所有的测试手机(Galaxy Captivate、Vibrant、Nexus 1、G Tablet、Archos 32、Droid)上都运行良好。我刚拿到一个 Droid 3 进行测试,在这部手机上,没有项目的列表视图的背景是灰色的。列表项具有正确的黑色背景。

这是包含列表视图的布局。 listview上下都有白色背景文本框,listview的背景是drawable(我知道它叫三边框,但它只是一个二边框)。

<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 层,所以我尝试在我的可绘制对象上取消前导 FF,但结果相同。

有人有什么想法可以解决这个问题吗?在一部不错的手机上看起来真的很丑。

谢谢, 格雷格

【问题讨论】:

  • 想补充一点,Droid 3 是 2.3,但 Nexus 1 也是,所以我不认为这是 Android 的东西。其他设备都是2.2。
  • 玩这个。如果我将可绘制对象中的外部形状更改为蓝色,则外部线条会在列表视图的整个高度上变为蓝色,但内部保持灰色。如果我将可绘制对象的内部形状更改为蓝色,我会在列表项本身之间显示一条细蓝线,但同样,在列表项下方的空白区域中除了灰色之外什么都没有。因此,摩托罗拉不知何故覆盖了列表视图的默认背景显示行为。

标签: android listview background


【解决方案1】:

朋友在摩托罗拉论坛上发现了一条评论:

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

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,那么列表视图看起来与我所有其他手机相同。所以我不确定他们是如何计算页脚空间的——我不知道他们如何知道我有一个双层对象并且只是替换第二层。一定是发生了其他一些我只是不明白的事情,但它确实有效。

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

【讨论】:

  • 谢谢。这是一个很难找到答案的问题
  • 摩托罗拉的这个真的很愚蠢。我的应用程序开始在许多新的 Moto 设备上看起来很可悲,而我却不知道这一点......为什么他们会搞砸像这样的主要东西。
  • 感谢您的回答,就像pendak 说这是一个很难找到答案的问题,而找到这样一个易于实施的解决方案是一种解脱。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-02-10
  • 1970-01-01
  • 1970-01-01
  • 2013-02-12
  • 2020-03-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多