kmshack / Android-ParallaxHeaderViewPager

DEPRECATED
Apache License 2.0
1.39k stars 336 forks source link

Listitems of variable size? #15

Open thevarun opened 9 years ago

thevarun commented 9 years ago

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;
}
yolapop commented 9 years ago

I think I just got the problem that you described, do you know the workaround?

thevarun commented 9 years ago

No, I am waiting for a resolution of this issue before using the library myself.

xifan-xf commented 9 years ago

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;
}
yolapop commented 9 years ago

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.

yolapop commented 9 years ago

Turns out it still doing the uneven scroll when changing tabs. Did you make any change on the ScrollTabHolderFragment's adjustScroll?

xifan-xf commented 9 years ago

@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 .