I am trying to style my ListView with two 9-patch background images (16px * 9px), one dark image for default state and another green image for selected and pressed state.
It works except for just one problem that when I select or press one list item, it seems that the selected item overlap the next one a little bit as I can see some pixels of the green background image is on the top of next item.
How to fix that?
OK, I found I set a padding there...
Related
I'm having trouble highlighting selected item in ListView. Basically, I wanted to highlight selected item by applying an overlay ONLY on top of the item.
I have two 9-patch images which I originally used for normal/pressed state on list item background. However, the effect only apply to the background and not other view creating strage looking effect for us. We want to be able to highlight the view when selected.
I now set drawSelectorOnTop to true. I also use the pressed state background in listSelector as well. This create similar effect. However, the highlight item are now bigger than the rest although the image I use was perfectly fine as a background.
Basically, what we wanted to achieve is the same selector effect as seen on Google Play store, Google Play Music, Google Keep. My list item feature ImageView quite heavily and I want the selector to highlight over that but not the background.
Check this out:ListView - Highlight sub layout of item. I've implemented exactly what I think you're looking to do.
I have a problem that would be hard to explain. In my listview the list item's have imageviews. I would like to have an 'on click' or 'on pressed' effect that changes the background of the whole list row, and also the imageviews. I tried 2 approaches:
a) defining the xml selector state list for the row's layout
b) setting an onClickListener in java code
Option a) is no good because I can only change the items background and can't change the imageviews (defining a state list for imageviews is no good because it only works when the exact object is touched. and I want the effect whenever any location of the row is touched)
option b) works almost correct - i set the background resource for the layout of the list item and also change the image resource for imageviews. however, afterwards they stay like that. I am now wondering how can I change back to normal to achieve the effect of a short 'blink' in the java code. Just like with a button - you press it and it blinks orange for a split of a second.
PS: the permanent change of resources is important, because on press I open another activity with item's details and when I press the 'back button' the row looks like permanently selected.
I found a solution with using the OnTouchListener instead of onClickListener.
I have a list view which items use a rounded-corner image for a background. The thing is that when the user selects an item, the whole area (the rounded-corner image plus the small gaps which would complete the item to a rectangle) gets selected. How do I deal with this?
Thanks.
When a user selects an item Android displays the drawable specified by android:selectorDrawable, which is by default rectangular.
You'll have to replace this with your own selector drawable which has rounded corners.
I hope, my issue would be clear for you from my question title. I have three linear layouts in each row of the list view. One linear layout contains an Imageview and the other two linear layout contains text views. These three linear layouts comprise my list view row. But, to my surprise, the listview default selection(orange colored) does not work when I move the trackball of mouse or when I select it from the phone.
Can anyone guide me resolve this issue.
Any help is appreciated.
Looking forward..
By default, the list selector is drawn behind the currently selected item. If your item layout has an opaque background, the selector cannot be seen.
Try making your list item background transparent.
Did you add a background color to your row's layouts? If so, that color will be the only color you see - even on touch events.
A row's background should really be set to a selectable drawable with different colors for different states like selected and unselected.
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.