Search code examples
androidandroid-toolbarandroid-collapsingtoolbarlayoutandroid-appbarlayout

Extra space between Collapsing Toolbar Title when expanded


I am facing problem for reducing left spaces of the Collapsible Toolbar Layout title. I want to align the title just below of the back button and I am unable to reduce the space. Thanks in advance. Here is the code.

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:fitsSystemWindows="true"
    tools:context="com.example.ManualConfigActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/scale_140dp"
        android:background="@color/white"
        android:theme="@style/AppTheme.AppBarOverlay"
        app:elevation="@dimen/scale_0dp">

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/white"
            android:fitsSystemWindows="true"
            app:collapsedTitleGravity="center_horizontal"
            app:expandedTitleGravity="bottom"
            app:toolbarId="@+id/toolbar">

            <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@color/white"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/AppTheme.PopupOverlay">

                <TextView
                    android:id="@+id/tv_back"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="start"
                    android:background="@drawable/ic_back"
                     />
            </androidx.appcompat.widget.Toolbar>

        </com.google.android.material.appbar.CollapsingToolbarLayout>
    </com.google.android.material.appbar.AppBarLayout>

    <include
        android:id="@+id/content_scrolling"
        layout="@layout/menu_content_scrolling" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

Solution

  • You forget to add app:layout_scrollFlags="scroll|enterAlways" in CollapsingToolbarLayout & if possible please attach the issue picture because it is easy to understand others