is there a way in android to make it so that an item or title type item sits at the top of the view of a list view? I want a section title to sit at the top of the visible part of the list view until the next one comes to the top and replaces it.
Check out the PinnedHeaderListView and the android-amazing-listview projects. They both provider ListViews with pinned header capabilities.
I suggest you use this library PinnedHeaderListView
github.com/mldeng/PinnedHeaderListView
This will definetely help you achieve exactly what you want.
Related
I'm looking for a way to expand list view header when the list is overscrolled.
Very similar to pull to refresh design but I need this expanded panel to remain visible until I explicitly close it (via some button or action).
It could be a list view header or some other View above the list view which is hidden.
I've failed to find any ready-to-use libraries, I've failed with customizing pull to refresh library by adding a custom animation layout and it also does not work (look good) with SlidingUpPanel because the content of dragable panel when located at top is shown inverted (bottom views displayed first, top views are off the screen)
Please advise hot to approach this task, thanks !
As per screen 1, I have one Title view, and a listview below it,
I want to place a 'hidden view' above this 'title view' which will be visible only when I have scrolled this list till the top.
I have seen Hide your actionbar
and QuickReturnListView and ObservableScrollView
but as I understand none of them serves my purpose. Do anybody know how to achieve something like this?
You made one of the awesome question. I will just suggest creating one custom layout which will get added into the header of the ListView, and that custom layout contains these two views one is always 'visible' and other view in default 'gone' mode and while the time of refresh makes it 'visible'. or you can use addHeader method while on start and end refresh.
listView.addHeaderView(headerView);
I hope this suggestion will work, "Best of Luck...!!"
"Happy Coding...!!!"
I have a ListView with a HeaderView.
I want one of the views in the HeaderView to stick on top.
I've seen a lot of examples for sticky Section Headers.
I also looked at StickyScrollViewItems but since I'm using a ListView, I cannot use a ScrollView.
Is there a library available for this or should I just override the OnScrollListener of the ListView?
Thanks.
I have just written a load of code that does this that I cant share for contractoral reasons. Basically follow the approach outlined here and apply to a listview rather than a scroll view.
Main points are
Create a wrapper view that contains your floating/sticky header and your listview as siblings
Use a proxy method when adding headers with an isSticky boolean - if is sticky then add a fake blank header to the listview of the same size and your intended header view to the floating header wrapper (use a relative layout here)
Set a scroll listener of the listview that tracks the top px position of the dummy header view in the list and setting this as a top margin of the floating header that sits inside a relative layout
Handle all the annoying edge cases / OEM overscroll crap to get it to work in all situtions (like this for samsung)
Remember to set the initial position of the floating/pinned header after the listview has been layed out.
I feel its a little bit involved and takes some tweaking to get right - this is a time where i envy iOS and any iOS devs will think your slacking as it takes a while to implement :D
All the Open libs out there at time of writing are using scroll views or list view headers. This issue with these approaches are that list views recycle views (so unlike scroll views you cant just keep a ref to the dummy view) and also the current libs seem duplicate the sticky views using adapter getView methods and so on - which is no good for dynamic list view header views as they are not recycled and can only have one parent, so reparenting would be annoying (and in my case has a lot of functionality so I defo dont want to create two views of the same type and shoehorn the current libs to fit my solutions)
I don't know of any library that lets you do this but what I do for a header is to use a RelativeLayout for my xml that will have the ListView. Then create your header view however you want and give it the property
android:layout_alignParentTop="true"
then give your ListView
android:layout_below="#id/idOfHeaderView
This is the easiest way I know of to dock a header view at the top. It has worked for me every time. I hope this helps.
I need to implement list view that must show selected item in the center of list view.
Is it possible?
The problem is that list view forbid scrolling before top item and after last item.
The only workaround here I found is to add several dummy header and bottom items and use setSelectionFromTop() method for right positioning.
Is there any other better way?
Thanks
You could use a circular ListView Check this thread on how to implement it
and use smoothScrollToPosition to bring your particular view to the center.
You shouldn't need to add multiple dummy list items. Just extend your Adapter and use a single blank dummy list item that you can programmatically adjust the size of based on the screen resolution of the device.
is it possible to programmically force a View inside a ScrollView NOT to scroll?
Like the alphabetic titles in the contacts list. The 'A' bar doesn't scroll when the user scrolls through the list of all contacts whose first names start with 'A'. When the user scrolls till the end of 'A', 'B' bar simply scrolls up from the bottom of ScrollView, finally reaplacing 'A' at the top and staying there.
My description is kind of abstract, hope you understand.
Also thanks in advance.
The contacts list uses the ListView and not the ScrollView. One way I think it can be done is to have a fixed header at the top. You can change its content depending on what is being displayed on the screen.
Attach a OnScrollListener to ListView. You will get the view with the first visible position in onScroll. Then change the content of the header according to the content in the view.
You don't need to add a header in your ListView for the first section in your list as it will be already handled in your ScrollListener. Keep the style for the header rows and the view at the top the same and you will have the illusion for the fixed header.
I think you need a combination of the "static text" approach with "section headers" within the ScrollView: the list should contain disabled/non-clickable items with the letters "A", "B", etc. When a section header scrolls above the top of the view, change the contents of the static TextView above the ScrollView to the contents of the header. I.e., when the "B" header item scrolls out of view, the TextView now contains "B".
Of course, the tough part will be detecting when a "section header" scrolls off the top, or comes into view when scrolling in the opposite direction.
For bonus points, use a "push up" Animation in the TextView when it's contents change to make it look like the list item is rolling into the TextView. (There is an example of this Animation in the API Demos app in the SDK in "...\view\Animation2.java").
UPDATE: after further review... here is some classes, etc. related towards making this work (it was a fun exercise for me!):
android.widget.AbsListView.OnScrollListener interface to see how to detect scrolling events. You'll need to keep track of the previous "top of view" position to determine which direction you are scrolling (to pick the slide-up or -down animation).
The Animation I listed above is not really what you want -- better off to look at the android.widget.TextSwitcher class and the push*.xml files in the SDK/android-X/data/res/anim directory.
You'll certainly need your own adapter subclass to inject section views into the list: getView(...) can set the row view's properties (bkgnd, text style, etc.) differently if the row is a section header or not. Re-use this code in your TextSwitcher view factory to populate the static TextView/Switcher above the list.
Have fun...!
As mentioned earlier you need a ListView. For an effect similar to that in the People app in Android 4+ I have used this excellent library (free and open source).