2

This is my situation:

enter image description here

I would like the list to treat the "header" and tabs sections as a list header so that the "header" and tabs do not stay fixed on the screen and they all scroll together with the list.

I can't simply add the header and tabs as a headerView for the list via mListView.addHeaderView() because the tabs will swap out the "List" content area when pressed. The content area for the other tabs will contain other lists, and the header and tabs should scroll with the new list as well.

I'd appreciate any help.

James
  • 5,273
  • 10
  • 51
  • 76

3 Answers3

0

You can override the getViewType method in order to precise how many kind of rows you listview has.

Have a look here.

Community
  • 1
  • 1
S.Thiongane
  • 6,883
  • 3
  • 37
  • 52
0

Think of the entire thing as the ListView. You can call addHeaderView() as many times as you want so you can have two header views ("Header", and "Tab | Tab | Tab").

Re:

I can't simply add the header and tabs as a headerView for the list via mListView.addHeaderView() because the tabs will swap out the "List" content area when pressed.

Yes you can.

Update the reference to your list data and call mAdapter.notifyDataSetChanged().

dcow
  • 7,765
  • 3
  • 45
  • 65
0

I had the same need as you, I found this project that implements exactly what you need, plus some more eye-candy tricks.

https://github.com/kmshack/Android-ParallaxHeaderViewPager

The magic is binding the scrolling that happens in the fragment list to the header defined in the activity. There is also a fundamental binding between the selection of a tab and the scroll position in the list, to adjust lists when swiping. This code is based upon that github repo but is simpler (therefore less robust), read it just to understand what happens, then read the source in the repo.

public class MyFragment extends Fragment implements OnScrollListener {
  @Override
  public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
      ((MyParentActivity) getActivity()).onScrollFragment(view, mTabPosition);
  }

  public void adjustScroll(int scrollHeight) {
    if (scrollHeight == 0 && fragmentListView.getFirstVisiblePosition() >= 1) {
        return;
    }

    officesListView.setSelectionFromTop(1, scrollHeight);
  }
}

then in the activity you just need these two specific methods

public class MyParentActivity implements ViewPager.OnPageChangeListener{
  @Override
  public void onPageSelected(int position)
            myFragmentPagerAdapter.getFragmentAt(position)
                                  .adjustScroll((int) (mHeader.getHeight() + ViewHelper.getTranslationY(mHeader)));      
  }

  public void onScrollFragment(AbsListView view, int tabPosition) {

        if (mViewPager.getCurrentItem() == tabPosition) {
            int scrollY = getScrollY(view);
            ViewHelper.setTranslationY(mHeader, Math.max(-scrollY, mMinHeaderTranslation));
        }
  }
}

this code is good up to API 8 thanks to NineOldAndroids' ViewHelper

vfede
  • 106
  • 1
  • 6