From 696c9c002f79d33b4c2cc2a2dcb2972ce9ca2994 Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Wed, 25 May 2022 10:52:14 +0200 Subject: [PATCH] Disable floating headers when we cannot scroll If recyclerView content is smaller then the recyclerView, we can already see all headers. Change-Id: I1b3b1506236701b75777d97a6fe759b2296f5db0 --- .../de/spiritcroc/recyclerview/StickyHeaderItemDecoration.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/vector/src/main/java/de/spiritcroc/recyclerview/StickyHeaderItemDecoration.kt b/vector/src/main/java/de/spiritcroc/recyclerview/StickyHeaderItemDecoration.kt index 4d7e66dbb4..32963a7541 100644 --- a/vector/src/main/java/de/spiritcroc/recyclerview/StickyHeaderItemDecoration.kt +++ b/vector/src/main/java/de/spiritcroc/recyclerview/StickyHeaderItemDecoration.kt @@ -52,6 +52,10 @@ abstract class StickyHeaderItemDecoration( if (parent.childCount == 0) { return } + if (!parent.canScrollVertically(1) && !parent.canScrollVertically(-1)) { + // No floating header needs if we cannot scroll, i.e. all headers are already visible + return + } val topChild = if (reverse) { parent.getChildAt(parent.childCount - 1) ?: return } else {