Tôi có hoạt động với một số CoordinatorLayout
, AppBarLayout
, CollapsingToolbarLayout
và Toolbar
. Vì vậy, về cơ bản, một chế độ xem thu gọn khi cuộn một số RecyclerView
.Hiển thị chế độ xem khi thanh công cụ thu hẹp
Điều tôi cần làm là hiển thị chế độ xem tùy chỉnh khi chế độ xem bố cục được mở rộng bị ẩn do thu gọn.
Đây là cách bố trí của tôi:
<android.support.design.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="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="192dp"
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="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="#2196F3"
app:expandedTitleMarginBottom="32dp"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<include
android:id="@+id/header"
layout="@layout/header_big_first_screen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"/>
<android.support.v7.widget.CollapsingToolbarLayout
android:id="@+id/anim_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Hello!"/>
</android.support.v7.widget.CollapsingToolbarLayout>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/categories_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
Cuối cùng, khi thanh công cụ được mở rộng quan điểm nạp với nguyên tố này được hiển thị. Khi nó sụp đổ thì không. Khi nó biến mất, TextView
bên trong Toolbar
sẽ được hiển thị. Hiện tại nó hiển thị mọi lúc.
Tôi đã tìm kiếm các sự kiện của CollapsingToolbarLayout
để thêm người nghe khi thay đổi kích thước để tôi có thể kiểm tra xem đó có nhỏ hơn giá trị và hiển thị chế độ xem đó hay không.
Điều này có thể khá khó giải thích nhưng tôi tin rằng tôi đã tự làm rõ. Tôi đã googling xung quanh và không thể tìm thấy bất cứ ai cố gắng để làm như vậy.
Bạn có thể sử dụng contentScrim không? – tachyonflux
@karaokyo setContentScrim và các biến thể của nó chỉ dành cho drawables và màu sắc, trừ khi tôi đang thiếu thứ gì đó. https://developer.android.com/reference/android/support/design/widget/CollapsingToolbarLayout.html –