我已经创建了一个特定的列表,它存在于以下元素中,以创建一个可滚动的列表,每一行都包含左侧的图像和右侧的一些文本:

从“根”布局开始:

<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="#C8C8C8"
    >
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>
    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:drawSelectorOnTop="false"
        android:divider="#C8C8C8"
        android:background="#C8C8C8"/>
</LinearLayout>

然后在ListView中,我放置以下“row”项:

<?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="wrap_content"
    android:orientation="horizontal"
    android:background="@drawable/bg_row"
>
    <ImageView
        android:layout_width="wrap_content"
        android:paddingLeft="10px"
        android:paddingRight="15px"
        android:paddingTop="5px"
        android:paddingBottom="5px"
        android:layout_height="wrap_content"
        android:src="@drawable/bg_image"
    />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingTop="5px"
        android:paddingBottom="5px"
        android:textSize="16sp"
        android:textColor="#000000"
        android:layout_gravity="center"
        android:maxHeight="50px"/>
</LinearLayout>

As long as the screen is shown statically (as in no movement) it will be shown correctly, but when I start scrolling through the list the background of the row-item (an "icon" as can be shown in the code) will be shown correctly but the background of the "root" layout will become completely black... when the scrolling stops the background will, most of the times, get back its color... As I test I also added a TextView in that root-element with the same background, this one will detain it's color when the List is scrolled... Any idea why this is happening, and how to solve this?


当前回答

对于这个问题我们有很多的选项,你可以通过编程把背景设置为透明的

yourlistview.setCacheColorHint(Color.TRANSPARENT); 

或者通过XML

android:cacheColorHint="@android:color/transparent"

其他回答

android: id =“@android: id /列表” android: layout_width = "宽和" android: layout_height = "宽和" android: drawSelectorOnTop = " false " android:分频器= " # C8C8C8” android:背景= " # C8C8C8” android: cacheColorHint = " # 00000000 " / >

你可以这样用:

list.setCacheColorHint(Color.TRANSPARENT);
list.requestFocus(0);

在ListView标签上添加一个属性

android:cacheColorHint="#00000000" // setting transparent color

欲了解更多细节,请查看此博客

我在listView中使用图像,它有时在三星s4中变成黑色,甚至没有滚动。这是我在适配器中犯的一个愚蠢的错误。我只是把我的视图为null来解决这个问题

 @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            Holder holder;
            convertView = null; // convert view should be null
            if (convertView == null) {
                holder = new Holder();
                convertView = inflater1.inflate(R.layout.listview_draftreport_item, null);
             } 
        }

对于这个问题我们有很多的选项,你可以通过编程把背景设置为透明的

yourlistview.setCacheColorHint(Color.TRANSPARENT); 

或者通过XML

android:cacheColorHint="@android:color/transparent"