android - 在选定的 ListView 上设置背景?

标签 android listview background

我有以下 2 个布局文件来显示联系人组列表。正常状态下的 View 看起来很完美。我背景上的半透明列表项。当我触摸列表以移动它时,背景变为黑色而不是保持半透明。

gouplist.xml

<?xml version="1.0" encoding="utf-8"?>
<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/megaphone_320x480">
    <ListView 
        android:id="@+id/android:list" 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        />
    <TextView 
        android:id="@id/android:empty" 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:text="No Groups" 
        />
</LinearLayout>

two_line_list.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView 
        android:id="@+id/lv_topText"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:textColor="#BBBBBB" 
        android:background="#99000000"
        android:textSize="24sp" 
        android:typeface="sans" 
        android:textStyle="bold"
        />
    <TextView 
        android:id="@+id/lv_bottomText"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:textColor="#BBBBBB" 
        android:background="#99000000"
        android:textSize="18sp" 
        android:typeface="sans" 
        android:textStyle="bold"
        />
</LinearLayout>

最佳答案

cacheColorHint 属性需要在实际的 ListView 上设置,就像这样。正如 3dmg 所述,它通常会设置为与 ListView 所在容器相同的背景颜色。在下面的示例中,ListView 将位于同样具有白色 (#FFF) 背景的 LinearLayout 内。

<ListView
    android:id="@+id/android:list"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1.0"
    android:cacheColorHint="#FFF" />

关于android - 在选定的 ListView 上设置背景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5325329/

相关文章:

android - 图像在 ListView 中随机播放。滚动时

css - :after :before selector 的不同配色方案

Android 在其他应用程序之上绘图 >23 API

android - 如何更改抽屉导航中的标题

android - 系统共享库和你自己的库在android上有性能差异吗?

android - 如果需要 8k 字符的缓冲区,最好明确说明。 [错误]

java - 选择并突出显示自定义 ListView 项目

java - Picasso 图片加载回调

html - CSS Class里面的背景图片到<div>

android - 如何将背景图像添加到 Activity ?