Custom ListView background problem - android

I have a LinearLayout layout with a ListView in it. I've made the android:background of the LinearLayout (I've also tried it on the ListView) be an image that I would like for my background.
This works fine enough. However, when I start scrolling through the ListView, the background often disappears and becomes black. If I move it around some more I may be able to get it to appear again. It would seem that Android is drawing over, or perhaps painting what's behind my background onto the items.
Any ideas/solutions?

android:cacheColorHint="#00000000" on your listview
More info is here
http://www.curious-creature.org/2008/12/22/why-is-my-list-black-an-android-optimization/

Related

How to prevent ListView items highlighting in Black

I have been trying desperately to fix this issue where my ListView items are highlighted. I have reviewed any solution I could find here on stackoverflow, and have found none that work for me.
First off, this is a ListView in a LinearLayout in a ViewPager in a LinearLayout.
Each Item in that Listview is a LinearLayout containing a LinearLayout (Containing a TextView) and a Gallery. The Gallery contains multiple LinearLayouts containing a TextView and Imageview in a FrameLayout.
This problem occurs, not on click but on drag, as when swiping your finger over a story (sometimes while the ListView scrolls with your drag) the item underneath becomes selected. Additionally, this particular problem only occurs on devices where the over-scroll effect does not cause a bounce when scrolling.
Attempts to solve the issue are as follows:
Set the List Selector to the Background Color in XML (Fail)
Set the List Select to Alpha #00000000 in XML (Fail)
The Above but Programatically
The Above but by theme
Code that sets the selection to -1 onListItemClick
Removing the background from list item's LinearLayout (Works on 4.0)
Setting android:cacheColorHint to #00000000 (does nothing?)
I just can't figure out why it's doing this and I really need it to stop.
This was a most interesting problem. The solution of which is even more interesting.
For some reason, what I didn't try, and what nobody thought of, was to remove android:background from the LinearLayout for the ListView items.
Upon removing android:background, the layout continues to display properly and the black no longer appears.
If you have a problem similar to this that this does not solve, you may want to check the Android Blog: Why is my list black?
EDIT: This worked fine for ICS, but elicited a much larger problem in 2.1. To completely solve the ordeal, I ended up having to specify android:cacheColorHint="#000000" to the ListView (and the LinearLayout for good measure) in my inline styles as well as in the style definition I applied to the ListView.

Changing UI elements while scrolling

I have a Layout with a ToggleButton and a gallery.
I'd like to change the toggleButton when I'm scrolling, I've implemented OnItemeSelectedListener and depending of the object I'm setting the button checked or not.
The thing is that the scroll freezes when the ToggleButton is changing, I know that there is only one thread for the UI but could I improve it?
I've seen apps like the CNN one which changes items like a textView color while scrolling, so should be a way...
The problem was the ToggleButton, I can change drawables, textviews and other items whitout problems but it seems that ToggleButton.setChecked is a slow code.
Finally I have two ToggleButtons overlapped, one to on and the other one to off and I make the top one visible or invisible.. apparently it's the same and it faster now :).

android appwidget invalidate

I have a home screen widget that tries to mimic a list of items, basically it's just 4 views in a vertical linear layout and there's 2 arrow buttons to "scroll" through list.
I'm able to scroll just fine querying the provider using limit offset, count.
The problem is that i'm using a transparent background and when i switch to the next set of results, the text of the item draws over the previous ones. It's like that view doesn't get invalidated.
Has anyone experience something like this? I tried using an opaque background and of course it works but i wanted a transparent one. I tried searching, but haven't found nothing like this.
Thanks,

Weird list behavior in android

I have an ImageView on top of a ListView and whenever there is a long running process to populate the list I would like to hide the ListView and make the ImageView visible.
I tried some things with setVisibility() but I'm getting messed up scroll behavior for the list.
I'm using AsyncTask to manage all this but I don't think that's causing the messed up scrolling behavior. Any ideas on how I can display a busy spinner while the list is being populated and not get inconsistent scrolling behavior for the list?
As far as the weird scrolling behavior you may need to set this property on your listview android:cacheColorHint to #00000000
Otherwise it will do weird things when there is an image under the ListView while scrolling.

How to do the following in ListView

How to do the following stuffs in ListView
Only show scroll bar when user flip the list.
By default, if the list is more than the screen, there is always a scrollbar on the right side.
Is there a way to set this scrollbar only shows when user flip the list?
Keep showing the list background image when scrolling.
I've set an image as the background of the ListView, but when I scroll the list, the background image will disappear and only shows a black list view background.
Is there any way to keep showing the list background image when scrolling?
Don't show the shadow indicator.
When the list has more items to display, there is a black-blur shadow to indicate user
that there are more items. Is there a way to remove this item?
The issue with the black background is easy to fix. It's an issue with the cacheColorHint - a way to tell Android what the background color of your list is so that it can more easily create the "fading edge" at the top and bottom of your list when the user is scrolling. However, if your background isn't a solid color then the cacheColorHint does more harm than good. See this post from the Android developer's blog for more information. The way to fix it is just to add this to your ListView xml:
android:cacheColorHint="#00000000"
You can change that color code to whatever you want; it's in AARRGGBB format, also sometimes known as HTML color codes but with an extra 2 digits in front for transparency.
As for removing the scrollbar unless the user is actually scrolling, I'm not sure. Experiment with the various android:scrollbar... settings. If you're using Eclipse, you can type out android:scrollbar and then hit ctrl + spacebar to make it suggest options.
You can just turn scrollbars on and off using setVerticalScrollbarEnabled(). The "shadow" indicator is called the fading edge in our APIs. There are various methods to control the fading edges in the base View class.

Categories

Resources