florent37 / MaterialViewPager

A Material Design ViewPager easy to use library
https://www.fiches-plateau-moto.fr
Apache License 2.0
8.13k stars 1.48k forks source link

Header collapses suddenly with ScrollView #266

Open vanjavanjavanja opened 8 years ago

vanjavanjavanja commented 8 years ago

Actual result: https://youtu.be/CPMFZ-bszAQ

Fragment code:

@Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        ObservableScrollView scrollView = (ObservableScrollView) view.findViewById(R.id.scrollView);
        RecyclerView recyclerview_matches = (RecyclerView) view.findViewById(R.id.recyclerView);

        adapter_team_matches = new TeamMatchesAdapter(getActivity(), new ArrayList<MatchList>());
        recyclerview_matches.setHasFixedSize(true);
        recyclerview_matches.setLayoutManager(new LinearLayoutManager(getActivity()));
        recyclerview_matches.setAdapter(adapter_team_matches);

        MaterialViewPagerHelper.registerScrollView(getActivity(), scrollView, null);

    }

Layout:

<com.github.ksoichiro.android.observablescrollview.ObservableScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <include layout="@layout/material_view_pager_placeholder"/>

        <android.support.v7.widget.RecyclerView
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            />

    </LinearLayout>

</com.github.ksoichiro.android.observablescrollview.ObservableScrollView>

Please help to understand what is wrong w/ my code, thanks!

vanjavanjavanja commented 8 years ago

Up this problem

vanjavanjavanja commented 8 years ago

Does anyone support the lib?

vanjavanjavanja commented 8 years ago

Hey anyone!

qingchengnus commented 8 years ago

I'm having the same issue, could anyone help me out? Thank you!

jintoga commented 7 years ago

I've faced the same issue and i'm using a hack to handle it. Something like this:

@Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser); 

        //hack: expand the header of Material ViewPager on tab selected
        if (mScrollView != null) {
            mScrollView.postDelayed(new Runnable() {
                @Override
                public void run() {
                    mScrollView.smoothScrollTo(0, 0);
                }
            }, 100);
        }
    }

Using this hack you can expand the header when a fragment is selected. Hope it helps!

chnouman commented 6 years ago

@jintoga how to use this method.