【发布时间】: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