2

I want to show a tab layout with an image that should be scrollable but then the tablayout is scrolled above it should remain fixed. In my case it also moves up with the scrolling. This is my final version of layout. Have tried so many things

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:elevation="2dp"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="300dp"
                android:background="@color/coupon_green"
                app:layout_collapseMode="parallax" />


            <android.support.design.widget.TabLayout
                android:id="@+id/profileTabLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:background="@color/white"
                android:elevation="2dp"
                app:layout_collapseMode="pin"
                app:tabIndicatorColor="@color/skill_black"
                app:tabMode="scrollable"
                app:tabSelectedTextColor="@color/skill_black"
                app:tabTextColor="@color/black" />


        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>


    <com.skillbox.ui.CustomViewPager
        android:id="@+id/profilePager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="bottom"
        app:layout_anchor="@+id/appBar"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</android.support.design.widget.CoordinatorLayout>
Gaurav Arora
  • 8,282
  • 21
  • 88
  • 143
  • (`app:tabMode="scrollable"` in the `tablayout`) whats the use-case of this ? Its already inside the collapsing toolbar layout !! – Santanu Sur Apr 28 '18 at 07:01
  • And also why the height of the collapsingtoolbar layout is `match_parent` ? it should be `wrap_content` or `300dp` – Santanu Sur Apr 28 '18 at 07:06
  • @SantanuSur FYI. You should read this: https://stackoverflow.com/questions/31190589/different-tabmode-for-tablayout – Gaurav Arora Apr 28 '18 at 07:15
  • @SantanuSur does the height of collapsingtoolbar really makes a difference if app bar is already wrap_content ? Read carefully – Gaurav Arora Apr 28 '18 at 07:18
  • if the parent layout is `wrap_content` child layout `match_parent` doesnt make sense.. even if it works code should be **`CLEAN`** !! – Santanu Sur Apr 28 '18 at 07:19
  • 1
    @SantanuSur I am trying to concentrate on pining the tablayout rather than enhancing the layout scheme – Gaurav Arora Apr 28 '18 at 07:20
  • as a workaround you can put the tablayout *out* of the collapsing toolbar layout and add `scrollFlags` to the collapsing toolbar layout as `enterAlways` **keep the tablayout and viewpager together in another layout** !! is the background of the tablayout affected by the imageView ? – Santanu Sur Apr 28 '18 at 07:25

0 Answers0