A sticky header is a UI element that stays fixed at the top of a scrolling list, so the header remains visible while the user scrolls through the content below it.
Click to reveal answer
intermediate
Which Android component is commonly used to implement sticky headers in a list?
RecyclerView is commonly used with custom adapters and layout managers to implement sticky headers by detecting scroll position and updating header views accordingly.
Click to reveal answer
intermediate
Name one popular library that helps implement sticky headers in Android Kotlin apps.
One popular library is 'StickyHeadersRecyclerView' which simplifies adding sticky headers to RecyclerView without complex custom code.
Click to reveal answer
beginner
How does a sticky header improve user experience in a long list?
It helps users keep context by showing the current section or category at the top, so they always know which part of the list they are viewing.
Click to reveal answer
advanced
What is a simple approach to create sticky headers without external libraries?
You can override RecyclerView's onScrollListener to detect the first visible item and update a separate header view fixed at the top accordingly.
Click to reveal answer
What UI component is typically used to create lists with sticky headers in Android?
AImageView
BTextView
CButton
DRecyclerView
✗ Incorrect
RecyclerView is designed for efficient scrolling lists and is commonly used to implement sticky headers.
What is the main benefit of sticky headers in a scrolling list?
AThey keep section titles visible
BThey add animations
CThey reduce app size
DThey disable scrolling
✗ Incorrect
Sticky headers keep section titles visible to help users understand the current list section.
Which method can be used to detect scroll position for sticky headers in RecyclerView?
AonClickListener
BonScrollListener
ConTouchListener
DonLongClickListener
✗ Incorrect
onScrollListener lets you track scrolling to update sticky headers.
Which of these is NOT a way to implement sticky headers?
AUsing a Button widget
BCustom onScrollListener logic
CUsing a fixed header view updated on scroll
DUsing a library
✗ Incorrect
Button widgets are not used for sticky headers.
Sticky headers help users by:
AMaking the app slower
BHiding the list content
CShowing the current section while scrolling
DChanging the font size automatically
✗ Incorrect
Sticky headers show the current section to keep users oriented.
Explain how sticky headers improve navigation in a long scrolling list.
Think about how you keep track of chapters in a book while reading.
You got /3 concepts.
Describe a simple way to implement sticky headers in a RecyclerView without external libraries.
Consider how you might watch the scroll and change a separate view at the top.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of sticky headers in an Android RecyclerView?
easy
A. To keep section titles visible while scrolling
B. To add animations to list items
C. To load images asynchronously
D. To sort the list alphabetically
Solution
Step 1: Understand sticky header behavior
Sticky headers keep section titles visible at the top as you scroll through grouped list items.
Step 2: Compare with other options
Animations, image loading, and sorting are unrelated to sticky headers.
Final Answer:
To keep section titles visible while scrolling -> Option A
Quick Check:
Sticky headers = visible section titles [OK]
Hint: Sticky headers keep titles visible on scroll [OK]
Common Mistakes:
Confusing sticky headers with animations
Thinking sticky headers sort the list
Assuming sticky headers load images
2. Which Android component is commonly used to implement sticky headers in Kotlin?
easy
A. RecyclerView with ItemDecoration
B. ListView with Adapter
C. ScrollView with LinearLayout
D. ViewPager with FragmentStateAdapter
Solution
Step 1: Identify components for sticky headers
RecyclerView supports ItemDecoration which allows custom drawing for sticky headers.
Step 2: Eliminate other options
ListView and ScrollView do not support sticky headers natively; ViewPager is for paging, not lists.
Final Answer:
RecyclerView with ItemDecoration -> Option A
Quick Check:
Sticky headers use RecyclerView + ItemDecoration [OK]
Hint: Sticky headers need RecyclerView + ItemDecoration [OK]
Common Mistakes:
Choosing ListView instead of RecyclerView
Using ScrollView which lacks sticky header support
Confusing ViewPager with list components
3. Given this Kotlin code snippet for a RecyclerView ItemDecoration:
override fun onDrawOver(c: Canvas, parent: RecyclerView, state: RecyclerView.State) {
val child = parent.getChildAt(0) ?: return
val position = parent.getChildAdapterPosition(child)
val header = getHeaderViewForItem(position)
c.save()
c.translate(0f, 0f)
header.draw(c)
c.restore()
}
What is the visible effect of this code when scrolling?
medium
A. The header blinks on every scroll event
B. The header stays fixed at the top while list scrolls underneath
C. The header appears at the bottom of the list
D. The header scrolls away with the list items
Solution
Step 1: Analyze onDrawOver behavior
onDrawOver draws the header on top of the RecyclerView content, fixed at the top (0f, 0f).
Step 2: Understand scrolling effect
Since header is drawn at fixed position, it stays visible while list scrolls underneath.
Final Answer:
The header stays fixed at the top while list scrolls underneath -> Option B
Hint: onDrawOver draws sticky header at fixed top position [OK]
Common Mistakes:
Thinking header scrolls away with items
Assuming header appears at bottom
Believing header blinks on scroll
4. You implemented sticky headers using ItemDecoration but headers flicker or disappear during fast scroll. What is the likely cause?
medium
A. Using LinearLayoutManager instead of GridLayoutManager
B. Setting RecyclerView height to wrap_content
C. Forgetting to call super.onDrawOver() in override
D. Not caching header views causing repeated layout calls
Solution
Step 1: Identify flicker cause in sticky headers
Repeatedly creating and measuring header views without caching causes flicker during fast scroll.
Step 2: Check other options
Layout manager type or calling super.onDrawOver() usually don't cause flicker; wrap_content affects layout size but not flicker.
Final Answer:
Not caching header views causing repeated layout calls -> Option D
Quick Check:
Missing header caching = flicker [OK]
Hint: Cache header views to avoid flicker [OK]
Common Mistakes:
Ignoring header view caching
Blaming layout manager type
Forgetting super call but unrelated to flicker
5. You want to implement sticky headers that change smoothly when scrolling between sections in a RecyclerView. Which approach best achieves this effect?
hard
A. Use a separate fixed TextView outside RecyclerView for headers
B. Replace header view completely on every scroll event
C. Draw the current header at top and translate it up as next header approaches
D. Disable RecyclerView animations to prevent flicker