Vista de lista de fondo se convierte en negro al desplazarse


He creado una Lista específica que existe de los siguientes elementos para crear una lista desplazable con cada fila que contiene una Imagen en el lado izquierdo y algo de texto en el lado derecho:

Para comenzar con un diseño "raíz":

<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>

Y luego dentro del ListView coloco el siguiente elemento "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>

Mientras la pantalla se muestre estáticamente (como en ningún movimiento) se mostrará correctamente, pero cuando empiezo a desplazarme por la lista el fondo del row-item (un" icono "como se puede mostrar en el código) se mostrará correctamente, pero el fondo del diseño" raíz " se volverá completamente negro... cuando el desplazamiento se detiene el fondo, la mayoría de las veces, recuperar su color... Como pruebo, también agregué un TextView en ese elemento raíz con el mismo fondo, este detendrá su color cuando se desplace la Lista... ¿Alguna idea de por qué está pasando esto y cómo resolverlo?

Author: KeLiuyue, 2010-05-14

11 answers

Añadir un atributo en la etiqueta ListView

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

Para más detalles consulte este blog

 767
Author: Praveen,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-09-27 09:38:16

Es muy simple simplemente use esta línea en su archivo de diseño :

android:scrollingCache="false"

Así:

<ListView 
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollingCache="false"
/>
 61
Author: Mahesh,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-11-22 08:03:07

Puedes usar así:

list.setCacheColorHint(Color.TRANSPARENT);
list.requestFocus(0);
 25
Author: nikki,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-08-30 12:58:19

android:id="@android:id/list"
android:layout_width="fill_parent" 
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"
android:divider="#C8C8C8"
android:background="#C8C8C8"
android:cacheColorHint="#00000000"/>
 8
Author: AnDx,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-05-08 04:26:51

Tenemos muchas opciones para este problema, puede establecer el fondo como transparente a través de la programación como

yourlistview.setCacheColorHint(Color.TRANSPARENT); 

O a través de xml

android:cacheColorHint="@android:color/transparent"
 6
Author: Sampath Kumar,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-03-18 05:22:35

Estoy usando imágenes en listView y a veces se vuelve negro en samsung s4 ni siquiera desplazándose. Fue un error estúpido que he hecho en el adaptador.Acabo de poner mi vista a null para solucionar este problema

 @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);
             } 
        }
 4
Author: Ahmad Arslan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-12-28 02:46:31

Hay un montón de respuestas a esta pregunta, pero hoy me di cuenta de que a esta pregunta todavía le falta una pieza crítica de información.

Hay dos posibles soluciones para el problema, ambas funcionan pero cada una debe usarse en diferentes situaciones.


Métodos

Use android:cacheColorHint cuando su ListView tiene un fondo de color sólido.

<item name="android:cacheColorHint">@android:color/transparent</item>

Use android:scrollingCache cuando su ListView tiene una (compleja) imagen como fondo.

<item name="android:scrollingCache">false</item>

Nota

Cuando su ListView tiene un fondo de color sólido, ambos métodos funcionarán, por lo que no solo el cacheColorHint funcionará. Pero no se recomienda utilizar el método scrolingCache para fondos de color sólido, ya que desactiva un método de optimización utilizado para la animación suave y el desplazamiento de la vista de lista.

Nota para la nota: scrolingCache establecer a false no significa necesariamente que las animaciones y el desplazamiento de ListView se vuelvan lentos.

 3
Author: Rolf ツ,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-12-28 02:44:24

En tu xml dónde usar Listview establecer

    android:cacheColorHint="@android:color/transparent"
 3
Author: jeet parmar,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-12-28 02:46:00
android:cacheColorHint="@android:color/transparent"
 1
Author: muditagarwal88,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-11-28 20:42:19

Lo siguiente funcionó para mí:

myListView.setScrollingCacheEnabled(false);
 1
Author: Lazy Ninja,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-02-01 07:37:07

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

O

no establezca el fondo de listview.

 0
Author: Akshay Paliwal,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-12-28 02:45:40