滚动时背景 ListView 变黑 [英] Background ListView becomes black when scrolling

查看:30
本文介绍了滚动时背景 ListView 变黑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have created a specific List which exists out of the following elements to create a scrollable list with every row containing a Image on the left side and some text on the right side:

从根"布局开始:

<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 中放置以下行"项:

and then within the ListView I place the following "row" item :

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

只要屏幕静态显示(如没有移动),它就会正确显示,但是当我开始滚动列表时,行项目的背景(可以在代码中显示的图标") 将正确显示,但根"布局的背景将变为完全黑色......当滚动停止时,背景将在大多数情况下恢复其颜色......当我测试时,我还在具有相同背景的根元素中添加了一个 TextView ,当滚动列表时,这个将保留它的颜色......知道为什么会发生这种情况,以及如何解决这个问题吗?

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?

推荐答案

ListView 标签上添加属性

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

有关详细信息,请查看此博客

这篇关于滚动时背景 ListView 变黑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆