This question is very specific. What I'm trying to do (with a list) is described in detail in the following article: http://www.pushing-pixels.org/2011/07/18/android-tips-and-tricks-synchronized-scrolling.html
Thanks @kaushal trivedi for the link
Details:
I have an Android application that I am working on and uses a list view with a custom adapter. Listview Contains a custom header at a fixed height. Also note that the list items also have a variable height. My goal is to simulate the effect created in the last gmail application (as an example), where when you look at email and scroll it by the title, it adheres to the top of the screen under the action bar and the content continues until you scroll under it. What I would like to do is stick to the bottom half of my heading at the top of the screen.
My initial thoughts were to create an invisible view fixed in the right place, and when the user scrolls to or past that location, make the view visible. The problem is this logic, I need an exact pixel scroll height, which, after many attempts that I determined, is very difficult to do. The exact problem I came across is not possible from what I can collect to get the Y-scrolling of the pixel level in the onScroll event, but I managed to get the value in the onScrollStateChanged event. Which, as described above, will not achieve the desired functionality.
Working with the onScroll event "int firstVisibleItem, int visibleItemCount, int totalItemCount" is also not a parameter due to the fact that the content I want to "stick to" is not the size of the list item, but part is the size of the variable-height header.
Is there a proper way to achieve this effect? My current minSDK level is 10.
Update 10/10/13
I have made some progress. The following code synchronizes the floating view of the Y position that I have on the screen with a list. b is the view that I set as an example.
NOTE. This is used in the event onScrollas a list.
View c = view.getChildAt(0);
if (c != null) {
int currY = c.getTop();
int diffY = currY - lastY;
lastY = currY;
b.setTop(b.getTop() + diffY);
}
, , . "b", , .
, .
header.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
header.getMeasuredHeight(); , .
, , . ?
10/11/13
, .
View.measure() . -, , , ( ). , , , ( , :))
ViewTreeObserver vto = header.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
b.setY(header.getMeasuredHeight() - 80);
}
});
, , . , . - .