Reputation: 5764
I have a listview with a layout which has an nested layout with a different background color to the main layout.
Inside this nested layout is an imageview. Whenever images are loaded into the view the background color of this nested layout disappears. The background does not come back until the listview is scrolled.
Also when scrolling the listview has the images in the imageview are drawn again this sequence happens again which gives the list a flickering effect.
I have tried setting cacheColorHint property on both the main layout and nested layout but it does not seem to change.
Here is an example image of what the happens when loading the images/scrolling. As you can see the background color for the two items at the bottom has disappeared and the rest still have their background color.
Here is the part of the listview layout with the nested layout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/race_entrant"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:paddingTop="2dip"
android:paddingBottom="2dip"
android:paddingRight="2dip"
android:orientation="horizontal"
android:descendantFocusability="blocksDescendants"
android:cacheColorHint="#E0EAF1">
<LinearLayout
android:layout_height="fill_parent"
android:layout_width="50dip"
android:orientation="vertical"
android:id="@+id/linearLeft"
android:paddingLeft="2dip"
android:paddingRight="2dip"
android:paddingTop="2dip"
android:paddingBottom="2dip"
android:background="#E0EAF1"
android:cacheColorHint="#E0EAF1">
<TextView
android:id="@+id/txtEntrantNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/entrant_number"
android:layout_gravity="center_horizontal"
android:cacheColorHint="#E0EAF1" />
<ImageView
android:id="@+id/imgJockey"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:layout_marginTop="1dip"
android:adjustViewBounds="true"
android:cacheColorHint="#E0EAF1" />
</LinearLayout>
How can I stop the background color of the nested layout from disappearing like this?
Upvotes: 1
Views: 1611
Reputation: 6640
This solves the problem for me: listView.setCacheColorHint(Color.TRANSPARENT);
This might just help someone.
Upvotes: 7
Reputation: 5764
I managed to get this to work by setting the background color of the imageview.
The xml to do this was:
android:background="#E0EAF1"
Now when the images are loaded the background color does not change.
Upvotes: 0