Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Toolbar overlapping TabLayout in CollapsingToolbarLayout

I'm trying to make CollapsingToolbarLayout with Toolbar and TabLayout below it, but they overlapping each other and I get this

enter image description here

I've tried many solutions, but still have this problem. Here is my xml:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:fab="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

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

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            app:contentScrim="@color/colorAppPrimary"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <RelativeLayout
                android:id="@+id/image"
                android:layout_width="match_parent"
                android:layout_height="250dp"
                android:background="@drawable/material_plane"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                android:src="@drawable/header_png"
                app:layout_collapseMode="parallax"
                app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed">

                <ImageView
                    android:id="@+id/imageViewPhoto"
                    android:layout_width="80dp"
                    android:layout_height="80dp"
                    android:layout_centerInParent="true" />

                <TextView
                    android:id="@+id/textViewName"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="false"
                    android:layout_below="@+id/imageViewPhoto"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="5dp"
                    android:text="TEXT"
                    android:textColor="@color/white"
                    android:textSize="16dp" />
            </RelativeLayout>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:fitsSystemWindows="true"
                android:gravity="top"
                app:layout_collapseMode="pin"
                app:layout_scrollFlags="scroll|enterAlways">

                <TextView
                    android:id="@+id/toolbar_title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:textColor="@color/white"
                    android:textSize="20dp"
                    android:textStyle="bold" />
            </android.support.v7.widget.Toolbar>

            <android.support.design.widget.TabLayout
                android:id="@+id/tabs"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:layout_gravity="bottom"
                android:fitsSystemWindows="true"
                app:tabBackground="@android:color/transparent"
                app:tabMode="scrollable" />

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

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

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</android.support.design.widget.CoordinatorLayout>
like image 789
Roman Svyatnenko Avatar asked Feb 05 '16 11:02

Roman Svyatnenko


People also ask

What is collapsingtoolbarlayout in Android?

CollapsingToolbarLayout is a wrapper for Toolbar which implements a collapsing app bar. It is designed to be used as a direct child of a AppBarLayout.

How to put the Toolbar inside the collapsingtoolbar?

Try to put the Toolbar inside the CollapsingToolbar with app:layout_collapseMode="pin" and the TabLayout outside with app:layout_scrollFlags="enterAlways"

How to make Tabs appear below appbarlayout in Android?

app:layout_anchor="@+id/appbar" and app:layout_anchorGravity="bottom" - To make sure tabs appear below AppBarLayout Also set android:layout_marginTop="?attr/actionBarSize" inside ViewPager to make sure TabLayout doesn't overlap any items in the list

Why is my imageview not under the collapsingtoolbarlayout?

The issue now is that the ImageView placed inside the CollapsingToolbarLayout will not be under the TabLayout but above it vertically. To solve this issue we need to make the ImageView taller so that if we were to place the TabLayout inside the CollapsingToolbarLayout it will cover it.


1 Answers

Try to remove this from your RelativeLayout:

app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed">

Or just let them be like this:

app:layout_scrollFlags="scroll|enterAlwaysCollapsed">

It was a bug i guess.


UPDATED: check this link: http://blog.grafixartist.com/parallax-scrolling-tabs-design-support-library/

And similar question: How to use a TabLayout with Toolbar inside CollapsingToolbarLayout?

<android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        app:contentScrim="@color/colorPrimaryDark"
        app:expandedTitleMarginEnd="64dp"
        app:expandedTitleMarginStart="48dp"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <RelativeLayout
            android:id="@+id/image"
            android:layout_width="match_parent"
            android:layout_height="250dp"
            android:background="@drawable/header"
            android:fitsSystemWindows="true"
            android:scaleType="centerCrop">

            <ImageView
                android:id="@+id/imageViewPhoto"
                android:layout_width="80dp"
                android:layout_height="80dp"
                android:layout_centerInParent="true"
                app:layout_collapseMode="parallax" />

            <TextView
                android:id="@+id/textViewName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="false"
                android:layout_below="@+id/imageViewPhoto"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="5dp"
                android:text="TEXT"
                android:textSize="16dp" />

        </RelativeLayout>

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:fitsSystemWindows="true"
            android:gravity="top"
            app:layout_collapseMode="pin"
            app:layout_scrollFlags="scroll|enterAlways">

            <TextView
                android:id="@+id/toolbar_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:textSize="20dp"
                android:textStyle="bold" />
        </android.support.v7.widget.Toolbar>

        <android.support.design.widget.TabLayout
            android:id="@+id/htab_tabs"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:layout_gravity="bottom"
            app:tabIndicatorColor="@android:color/white" />

    </android.support.design.widget.CollapsingToolbarLayout>
like image 142
ʍѳђઽ૯ท Avatar answered Sep 28 '22 05:09

ʍѳђઽ૯ท