How to do the following in ListView - android

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.

Related

Android - correct way to highlight multiple image items in Grid/Listview

I have a list view in my app with elements where an image covers pretty much all of the view. There was an article by google where they explain that selectors should be drawn on top of the item if the item's background is not visible or else you wont see the selection highlight. Can't find this article anymore.
The list view has been correctly configured with drawSelectorOnTop and a selector for various states. Each item on a list view is a RelativeLayout with a background selector for various states including activated. When selecting multiple items and marking them as checked, the items are correctly marked but since a big image covers almost all of the view, just a fraction of the background is shown in the highlighted color.
I fixed my problem by wrapping the relative layout into a frame layout and setting a foreground drawable to draw the highlights. It works, but I don't like adding the extra layout on my elements.
Ideally, the selector of the listview should be used to mark the items, but apparently not. I included all possible states on the list view selector but it never leaves the item highlighted.
My question is: is wrapping items in a framelayout the correct way of doing this or is there a better approach?

Android layout/control to show "arrow" from opened Tab to List/Menu?

I like the design of the Gmail app for android and I'm wondering if they created it using some standard approach.
I guess it uses fragments, one for the menu on the left side and another one for the content. But what looks really cool for me here is this little arrow pointing from the content to the selected item. It gives the feeling that the content page is placed on top of the rest.
Is something like this available out of the box?
I think they're using android:windowContentOverlay on the left side selected item where they show the "arrow"-like drawable. The drawable should have android:gravity="right" so it's placed correctly.
Of course, you would need to fine tune your layout to make it look "real", but I achieved some similar effects using this technique.
Looks like he is using 2 ListViews, and as far as that arrow I don't think it's available. I looked at a lot of 4.0 features but don't really see anything close to that. I'm thinking it could be part of the background for the right ListView?
Multipane Layout: left side a list fragment (or fragment with a recyclerview), right side a fragment with the content view (scrollview, listview, recyclerview, webview, etc.).
If the item on the left is selected (single selection model), the selector uses a different drawable for the selected state and updates the content on the right. Maybe the listview item has a additional padding on the end to avoid overlap with the arrow bitmap drawable that is used within the selector.
On Lollipop there maybe also an additional ripple effect on top (draw selector on top or use a specific drawable-v21 with ripple).
The drop shadow effect can be achieved with a framelayout in the left fragment (first member is the listview, second member is a view that displays the shadow (gradient drawable) as background with gravity set to end).

setting custom background overrides ListView customization

I've modified a list view to have a different selection color and item backgrounds. Things are working perfectly until I set a custom color on the application or activity background (solid color, png, gradient). I tried using cache color hint also, but it does not seem to work.
I've been on google pretty much the whole of yesterday and haven't found an answer. The closest I've come is this thread:
The gentleman seems to say that this is as designed. If it is I'd like to hear how I could change the background color of the entire list view (I'm talking about the area in the list view that may be empty).
If you want to look at some code you will find it here.
Thanks
Manish
I'm not entirely clear on what you are asking, so let me explain how all the items that you are playing with work together, and perhaps your answer will be in there somewhere. There are three distinct visual elements that you have described in your question:
A list item's background
The list selector
The overall ListView's background
By default, they will be drawn in that hierarchy, meaning (1) is drawn on top of (2), (2) is drawn on top of (3), and so on. On a ListView with no customization, items 2 & 3 are transparent and the selector is a drawable with multiple states. Because of this, any custom colors you apply to the Activity or any View beneath the ListView is going to show through, due to the transparency.
If you look at the order in which these things are drawn, you can start to see how customizing one element may cover up any customization done to another element. For example, if you set an opaque background on each item of the list, and listSelector attribute the list has will be completely covered up (unless drawSelectorOnTop is set...which is why when developer do that they provided a drawable with states as the background item).
ListView is just another view, and you may set its background attribute directly if you wanted to provide a background to the entire ListView and hide the Views displaying underneath it. Again, if you were to set a custom list item background, this would not be visible except for areas where the ListView is large enough to display all its elements and there is extra space below them.
The job of cacheColorHint is to optimize scrolling performance by telling each list item to draw itself with a solid color background (while scrolling) instead of being transparent. If you set a solid color background on ListView or the Activity beneath, this value should be set to the same color. If your background is a gradient or image, you cannot use this optimization and it should be set to transparent (i.e. #0000)
Hope that Helps.

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,

Android listview (array adapter) custom scrolling

I would like to change the default behaviour of my listview, so when im scrolling to the last item, the list will keep scrolling untill the last item is at the top of the list.
default behaviour stops scrolling when the last item is fully in view.
Any ideas on how i can go about this pre 2.3?
Thanks,
Totem.
In case anyone is interested in the solutions available it either:
1) add to the list view padding, that solution forces you to play around with the fading edge property since it gets sifted because of thee padding. also this method might not work well if your using a transparent background because items will be rendered and visible under the padding area. Although this could be fixed by entering the list into a relative layout and making sure to draw something over that area.
2) add transparent items to the listview for offset and not set them as enabled to avoid dividers, just need to make sure to change getItemCount and getItemTypeCount and so on if your if your item isn't really inside your adapter as per my case.
I went with option two.
Thanks,
Totem.

Categories

Resources