AndroidDeveloperLB / ListViewVariants

Provides special ways to handle ListViews, including PinnedHeaderListView in Lollipop's Contacts' app style
Apache License 2.0
334 stars 75 forks source link

header view should be invisible for top item (when the pinned header goes from an invisible to visible state) #7

Open cliffsun91 opened 9 years ago

cliffsun91 commented 9 years ago

Hi, great little library btw, we've had some issues with the default android listviews and different height cells (some cells are header sections) with, which has caused bugs on some devices when using fastscroll (with certain datasets in the list). Your little POC library is great because its fits in with the new android design and also works great as all the cells are the same heights.

I've been trying to integrate your code into an application I am working on, however I noticed that there are a few small tweaks that are needed. The main one being that if you were to set the backgroundColor of the header views to transparent/null (comment out 'mAdapter.setPinnedHeaderBackgroundColor(pinnedHeaderBackgroundColor);' in MainActivity), you'll notice that when you scroll up so that the first item of an alphabetical section becomes 'pinned' (i.e. the pinned header view becomes visible in that locked position on the screen), you'll see the header view for the cell behind it still. Your sample app doesn't show this normally as you explicitly set the background colour for the header views, however if you have an app with a common background (which has a gradient for example), you'd want to allow the background of the header view to be transparent.

I suspect that all we would need to do is in PinnedHeaderListView.configureHeaderView(int position) in the PINNED_HEADER_VISIBLE state is find the first visible element of the list and make the header view in that invisible. Oppositely when the pinned header goes into the PINNED_HEADER_GONE state (which seems to only happen when scrolling up between the beginning of a section and the end of the previous section) we should then find the first visible element of the list and make the header view visible.

AndroidDeveloperLB commented 9 years ago

Not sure I understand. Can you please show a gif animation of the issue? Also, this POC was made a long time ago, so I'm not sure how much I can be of assistance . :(

cliffsun91 commented 9 years ago

screenshot_2015-05-19-13-04-57 screenshot_2015-05-19-13-05-09

So i set the backgrounds for the header views (the A's) to null, i.e. transparent. You can see when I scroll up and the pinned header is anchored the header view attached to the list item itself is still visible. It wasn't visible originally as the background was set to an explicit colour (thereby hiding it).

I understand if you won't be able to do anything about it, I saw your last commit was a while ago. I like the library though, its small and simple and works quite well (and I haven't found anything else that isn't overly complicated like this). I can fix it myself but if I don't know if you'll be willing to take a pull request in the future at some point.

AndroidDeveloperLB commented 9 years ago

Using my sample, I can't reproduce the bahavior you are showing on the image. The headers aren't supposed to be duplicated this way. The code is written in a way that hides the header when needed. Also it hides the fact that the rows include the left area. I don't know what you change that caused it.

cliffsun91 commented 9 years ago

you don't have any code anywhere sets the header that is part of the row invisible (not the pinned/sticky one). I added some code to the PINNED_HEADER_VISIBLE and PINNED_HEADER_PUSHED_UP switch statements in configureHeaderView which finds the top (first visible) item/row in the ListView and sets the header TextView to invisible. I can't quite remember why we had to add the code to both switch statements, but I recall that the pinned header state that was returned wasn't very consistent with what was happening on screen.

You definitely commented out:

mAdapter.setPinnedHeaderBackgroundColor(pinnedHeaderBackgroundColor);

in MainActivity?

If you don't set a backgroundColor then the background is transparent and you should see the header TextView (which is part of the row) behind it.

AndroidDeveloperLB commented 9 years ago

Sorry, this was a long time ago so I don't remember exactly what I did, but I still can't reproduce what you've shown.

AndroidDeveloperLB commented 9 years ago

Does the sample work fine for you though?

praveen2gemini commented 8 years ago

@cliffsun91 I'm also getting this issue. But Applying same color code for Header view and List single item view we can hide the issue. This is not a standard solution. But It works.

Verdurakh commented 6 years ago

Maybe a little Necro but I had the same problem and it was solved by making sure that the color selected for the background has no alpha in it. for example setting it to Color.WHITE solved it for me