Android-ParallaxHeaderViewPager
Android-ParallaxHeaderViewPager copied to clipboard
Listitems of variable size?
Will this work properly if the row elements in the listview are of different sizes? The way getScrollY (on the basis of which Header is animated) is implemented, it looks as though scrolling will be smooth only if all elements are of equal size. Kindly correct me if I am wrong.
public int getScrollY(AbsListView view) {
View c = view.getChildAt(0);
if (c == null) {
return 0;
}
int firstVisiblePosition = view.getFirstVisiblePosition();
int top = c.getTop();
int headerHeight = 0;
if (firstVisiblePosition >= 1) {
headerHeight = mHeaderHeight;
}
return -top + firstVisiblePosition * c.getHeight() + headerHeight;
}
I think I just got the problem that you described, do you know the workaround?
No, I am waiting for a resolution of this issue before using the library myself.
i use staggergridview and the item are different sizes this is my solution:
mMinHeaderHeight = mHeaderHeight - mTabsHeight;
mMinHeaderTranslation = -mMinHeaderHeight;
public int getScrollY(StaggeredGridView view, int pagePosition) {
View c = view.getChildAt(0);
if (c == null) {
return 0;
}
int firstVisiblePosition = view.getFirstVisiblePosition();
View headView = ((PLA_ListView) view).getHeaderView();
if (Math.abs(ViewHelper.getTranslationY(mHeader)) == mMinHeaderHeight) {
if (headView != null && headView.getTop() <= mMinHeaderTranslation) {
return -mMinHeaderTranslation;
}
}
int top = c.getTop();
int headerHeight = 0;
if (firstVisiblePosition >= 1) {
headerHeight = mHeaderHeight;
}
return -top + firstVisiblePosition * c.getHeight() + headerHeight;
}
Thank you @xufan your solution worked. One thing that I have to be careful is to detect user scroll because if the adapter changes it will call onScroll too.
Turns out it still doing the uneven scroll when changing tabs. Did you make any change on the ScrollTabHolderFragment's adjustScroll?
@yolapop if you use something like StaggeredGridView,PLA_ListView .it don't implement smoothScrollToPositionFromTop or setSelectionFromTop method . so when changing tabs it won't work well. as far as i know ,in this lib only can use listview,scrollview&HeaderFooterGridView .