When you scroll through the list view, the background is black

Asked 2 years ago, Updated 2 years ago, 138 views

I made a scrolling list view. Each list has an image on the left and text on the right.

The root layout is

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

The elements in the list are

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

The first screen looks as good as I want. It's okay if you leave it alone, but when I start scrolling, the items in the row are printed well, but the root layout becomes completely black. Then, when I stop scrolling, the root layout returns to its original color after a while... I added a text view with the same background color to the root layout to experiment, but it's okay when I scroll... What's the problem? How do I solve this...?

android listview

2022-09-22 22:34

1 Answers

In the property tag of the list view,

android:cacheColorHint="#000000" // Transparent

Try adding this! Reference


2022-09-22 22:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.