android / architecture-samples

A collection of samples to discuss and showcase different architectural tools and patterns for Android apps.
Apache License 2.0
44.47k stars 11.64k forks source link

CollapsingToolBar not working on tab switch #888

Open AsitDixit opened 1 year ago

AsitDixit commented 1 year ago

When my activity is opened the first time I can collapse by dragging on the image but after switching to other tabs I can't collapse the layout by pulling on the image view. Once the view pager is scrolled, I can Collapse the toolbar using the top image view.Please look at the GIF on the link below. I think this is because of the view pager nested scrolling. I don't know the cause. but Why can't I drag the top Image view once the tab is switched?https://stackoverflow.com/questions/74611210/collapsingtoolbar-not-working-on-tab-switch

<?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:orientation="vertical"
    android:nestedScrollingEnabled="false"
    tools:context=".MainActivity">

<com.google.android.material.appbar.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:nestedScrollingEnabled="false"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<com.google.android.material.appbar.CollapsingToolbarLayout
    android:id="@+id/collapsingToolbarLayout"
    android:layout_width="match_parent"
    android:nestedScrollingEnabled="false"
    android:layout_height="256dp"
    app:titleEnabled="false"
    app:layout_scrollFlags="scroll|exitUntilCollapsed">
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/tool_bg"
        android:scaleType="centerCrop"
        app:layout_collapseMode="parallax"/>
    <View
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/black"
        android:alpha="0.3"/>
<androidx.appcompat.widget.Toolbar
    android:id="@+id/toolBar"
    android:layout_width="match_parent"
    android:layout_height="48dp"
     app:layout_collapseMode="pin"
    android:background="@drawable/fade"
    app:title="hello"

    android:layout_marginTop="4dp"
    android:layout_marginStart="5dp"
    android:layout_marginEnd="5dp"
    app:menu="@menu/three_line"
    android:layout_marginBottom="48dp"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    />
    <com.google.android.material.tabs.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:background="@android:color/transparent"
        app:tabSelectedTextColor="@color/white"/>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager2.widget.ViewPager2
    android:id="@+id/viewPager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>