我尝试了所有类似使用协调器布局设置滚动标志的方法,但是以前在没有androidx的情况下折叠工具栏似乎无法与android x一起使用,但我有一个可折叠的工具栏,但是在我看来,这根本无法正常工作,请看看在我的xml中,任何帮助将不胜感激:
main_toolbar:
<?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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsingToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlwaysCollapsed">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
app:contentInsetStart="0dp"
app:contentInsetRight="0dp"
app:contentInsetLeft="0dp"
app:contentInsetEnd="0dp"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/shuffle"
android:layout_width="@dimen/_45sdp"
android:layout_height="@dimen/_45sdp"
android:tint="@color/blue"
android:padding="@dimen/_5sdp"
android:src="@drawable/ic_shuffle_24px"
android:layout_alignParentTop="true"
android:layout_marginTop="@dimen/_10sdp" />
<ImageView
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_marvel"
android:layout_width="@dimen/_120sdp"
android:layout_height="match_parent" />
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/giftanim"
android:layout_width="@dimen/_55sdp"
android:layout_height="@dimen/_55sdp"
android:layout_centerVertical="true"
android:layout_marginRight="@dimen/_5sdp"
android:layout_toLeftOf="@+id/search"
app:lottie_autoPlay="true"
app:lottie_fileName="427-happy-birthday.json"
app:lottie_loop="true" />
<ImageView
android:id="@+id/search"
android:layout_width="@dimen/_45sdp"
android:layout_height="@dimen/_45sdp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:padding="@dimen/_5sdp"
android:layout_marginTop="@dimen/_10sdp"
android:tint="@color/blue"
android:src="@drawable/ic_search_24px" />
</RelativeLayout>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Activity_Main:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="bottom"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:background="@mipmap/thor1"
android:fitsSystemWindows="true">
<include android:id="@+id/tlb" layout="@layout/main_toolbar"></include>
<RelativeLayout
android:layout_width="match_parent"
android:id="@+id/main_ly"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_collapseMode="pin"
app:tabGravity="fill"
app:tabMode="scrollable"
android:elevation="@dimen/_20sdp"
android:theme="@style/TabLayout_Theme"
app:tabIndicatorColor="@android:color/holo_blue_dark"
app:tabSelectedTextColor="@android:color/holo_blue_light"
app:tabTextColor="#F5F4F4"></com.google.android.material.tabs.TabLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_marginTop="@dimen/_10sdp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_below="@id/tabLayout"
android:layout_marginBottom="@dimen/_60sdp"
android:layout_height="match_parent" >
<androidx.viewpager.widget.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
></androidx.viewpager.widget.ViewPager>
</RelativeLayout>
</LinearLayout>
<FrameLayout
android:id="@+id/fragment_content"
android:layout_width="match_parent"
android:visibility="invisible"
android:layout_marginTop="@dimen/_10sdp"
android:layout_marginBottom="@dimen/_65sdp"
android:layout_height="match_parent"></FrameLayout>
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/blastanim"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
app:lottie_autoPlay="true"
android:visibility="invisible"
app:lottie_fileName="7434-confetti.json"
app:lottie_loop="true" />
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="wrap_content"
android:id="@+id/btly"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content">
<include layout="@layout/bottom_sheet"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</RelativeLayout>
</LinearLayout>