ListView with a (half- and or) hidable header

2019-04-01 00:25发布

问题:

My Problem, is that I don't even know what to search for.

I want a ListView. This ListView has some Elements with a "sticky" state.

If I scroll down the List on the device, I want that all ListElements with state "sticky", to be sticky ontop of the list (non-scrollable) till there is another one "pushing it away". The rest of the elements are supposed to scroll as normal.

I've seen that kind of List in the Google Market. If you have a big screen you can see that list on the Detailview of any app on the left side or if you have android JB, the same effect is on the google search bar in the google now app.

Image One: You can see the normal ListView on the left side Image 1 http://www.android-hilfe.de/attachments/android-app-entwicklung/120884d1347256368-suche-stichwort-fuer-suche-nach-spezieller-listview-liste1.png

Image Two: You can see the normal ListView scrolled up a bit Image 2 http://www.android-hilfe.de/attachments/android-app-entwicklung/120885d1347256368-suche-stichwort-fuer-suche-nach-spezieller-listview-liste2.png:

Image Three: You can see, what I actually want. The View is scrolled up but the "sticky" price does not disappear. Instead of that all other elements, went under the "sticky" one Image 3 http://www.android-hilfe.de/attachments/android-app-entwicklung/120886d1347256368-suche-stichwort-fuer-suche-nach-spezieller-listview-liste3.png:

How do I do that?

回答1:

I think that you meant to do some "synchronized scrolling".

There's a great post explaining how they've done in on Google Play:

http://www.pushing-pixels.org/2011/07/18/android-tips-and-tricks-synchronized-scrolling.html

Hope that's what you were looking for..



回答2:

I believe that is a separate component, not related to ListView in any way.

Just create the header, let it be a RelativeLayout, or LinearLayout, and fill the rest of the area with the ListView set to fill_parent. Then, when you'll scroll the ListView, the "header" will stay sticky (as it is a separate component), and the list will scroll down.