2

My goal is putting header and footer to viewpager (where viewpager have child fragment of Recycle,Listviews etc .).when user scroll up i am setting setTranslationY to header and sticking the tabs of viewpager to toolbar .upto this everything is working fine but when Listfragment (inside viewpager) ends scrolling, the footer layout is not showing up .i am putting all three section(header ,viewpager with fragments ,footer) in scroll view.

UI structure is like ScrollView(RelativeLayout +ViewPager(4 different type of fragment)+ RelativeLayout). Please anyone who have done similar to this ,share me any link how to complete this.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/parent_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <ScrollView
        android:id="@+id/scroll"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:fillViewport="true">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="fill_parent">

            <android.support.v4.view.ViewPager
                android:id="@+id/view_pager"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/view_pager"
                android:text="jfgjfgj" />

            <LinearLayout
                android:id="@+id/header"
                android:layout_width="match_parent"
                android:layout_height="@dimen/header_height"
                android:orientation="vertical">

                <ImageView
                    android:id="@+id/image"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/parallax_image_height"
                    android:scaleType="centerCrop"
                    android:src="@drawable/course_ud" />


                <com.pace.bluewinger.activities.demo.slidingTab.SlidingTabLayout
                    android:id="@+id/navig_tab"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/tab_height"
                    android:background="@android:color/white"
                    app:indicatorColor="@color/theme_color"
                    app:shouldExpand="true"
                    app:tabBackgroundP="@layout/sliding_tab_view"
                    app:tabBackgroundTextViewId="@+id/tab_textview" />

            </LinearLayout>
        </RelativeLayout>

    </ScrollView>

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:minHeight="?attr/actionBarSize"
        app:popupTheme="@style/Theme.AppCompat.Light.DarkActionBar" />

</RelativeLayout>

I am using parallaxheaderviewpager libray to for header and retaining state of tabs for horizontal scroll of viewpager.

And in my activity -

@Override
    protected void scrollHeader(int scrollY) {

        float translationY = Math.max(-scrollY, mMinHeaderTranslation);
        mHeader.setTranslationY(translationY);
        int baseColor = getResources().getColor(R.color.primary);
        float alpha = Math.min(1, (float) scrollY / mParallaxImageHeight);
        mToolbar.setBackgroundColor(ScrollUtils.getColorWithAlpha(alpha, baseColor));

    }

viewpager adapter is extends from ParallaxFragmentPagerAdapter ,and layout of each fragment have height as wrap_content .

Or is there any other way to achieve above UI structure? Please help me out to complete it.

Anshul Kabra
  • 129
  • 17

1 Answers1

0

you cannot use ViewPager with dynamic height inside a ScrollView

change

android:layout_height="wrap_content"

to e.g.

android:layout_height="1000dp"

and it will work

  • 1
    i know setting fixed height to viewpager will show all the content.but it will give so much extra space in some child fragment of viewpager . – Anshul Kabra Mar 14 '16 at 06:15