This guide explains advanced features like Manual Rewind Gestures, Carousel Style, and more.
You can configure gestures that trigger a rewind when dragging, instead of removing the current card.
// Enable vertical swipes
manager.setDirections(Direction.VERTICAL)
// Configure Bottom swipe as rewind gesture
manager.setManualRewindDirections(listOf(Direction.Bottom))When the user swipes down, the previous card is brought back (if available), instead of removing the current card.
// Swipe horizontally (Left/Right)
manager.setDirections(Direction.HORIZONTAL)
// Left swipe brings back previous card
manager.setManualRewindDirections(listOf(Direction.Left))manualRewindDirectionsmust not contain any directions that are already enabled insetDirections(...)- If you try to use an already enabled direction, the LayoutManager throws an
IllegalArgumentException - This ensures swipe and rewind gestures remain distinct
// ❌ ERROR - Direction.Left is both in setDirections and setManualRewindDirections
manager.setDirections(listOf(Direction.Left, Direction.Right))
manager.setManualRewindDirections(listOf(Direction.Left)) // IllegalArgumentException!// ✅ CORRECT - Different directions
manager.setDirections(Direction.HORIZONTAL) // Left, Right
manager.setManualRewindDirections(listOf(Direction.Bottom)) // Bottom for rewindThe Carousel Style provides a carousel-inspired effect with curves and tilt.
val carousel = CarouselSetting(
orientation = CarouselOrientation.Horizontal, // or Vertical
scaleMultiplier = 0.18f, // Scale multiplier
minScale = 0.65f, // Minimum scale
tiltAngle = 8f // Tilt angle in degrees
)
manager.setStackStyle(CardStackStyle.Carousel)
manager.setCarouselSetting(carousel)
manager.setStackFrom(StackFrom.Bottom)
manager.setTranslationInterval(16f)| Parameter | Type | Description |
|---|---|---|
orientation |
CarouselOrientation |
Horizontal or Vertical |
scaleMultiplier |
Float |
Scale multiplier (0.0f - 1.0f) |
minScale |
Float |
Minimum scale for back cards (0.0f - 1.0f) |
tiltAngle |
Float |
Tilt angle in degrees |
val carousel = CarouselSetting(
orientation = CarouselOrientation.Horizontal,
scaleMultiplier = 0.18f,
minScale = 0.65f,
tiltAngle = 8f
)
manager.setStackStyle(CardStackStyle.Carousel)
manager.setCarouselSetting(carousel)
manager.setStackFrom(StackFrom.Bottom)
manager.setTranslationInterval(16f)val carousel = CarouselSetting(
orientation = CarouselOrientation.Vertical,
scaleMultiplier = 0.18f,
minScale = 0.65f,
tiltAngle = 10f
)
manager.setStackStyle(CardStackStyle.Carousel)
manager.setCarouselSetting(carousel)
manager.setStackFrom(StackFrom.Bottom)
manager.setTranslationInterval(16f)manager.setStackStyle(CardStackStyle.Stack)You can programmatically scroll to a specific position:
cardStackView.smoothScrollToPosition(5)cardStackView.scrollToPosition(5)manager.topPosition = 5You can change the configuration at runtime:
// Switch between horizontal and vertical swipes
fun switchToHorizontal() {
manager.setDirections(Direction.HORIZONTAL)
manager.setCanScrollHorizontal(true)
manager.setCanScrollVertical(false)
}
fun switchToVertical() {
manager.setDirections(Direction.VERTICAL)
manager.setCanScrollHorizontal(false)
manager.setCanScrollVertical(true)
}// Temporarily disable swipes
fun disableSwipes() {
manager.setSwipeableMethod(SwipeableMethod.None)
}
// Re-enable swipes
fun enableSwipes() {
manager.setSwipeableMethod(SwipeableMethod.AutomaticAndManual)
}private var isCarouselEnabled = false
fun toggleCarouselStyle() {
isCarouselEnabled = !isCarouselEnabled
if (isCarouselEnabled) {
val carousel = CarouselSetting(
orientation = CarouselOrientation.Vertical,
scaleMultiplier = 0.18f,
minScale = 0.65f,
tiltAngle = 10f
)
manager.setStackStyle(CardStackStyle.Carousel)
manager.setCarouselSetting(carousel)
} else {
manager.setStackStyle(CardStackStyle.Stack)
}
manager.requestLayout()
}val manager = CardStackLayoutManager(this, listener).apply {
// Stack Style
setStackStyle(CardStackStyle.Carousel)
setCarouselSetting(
CarouselSetting(
orientation = CarouselOrientation.Vertical,
scaleMultiplier = 0.18f,
minScale = 0.65f,
tiltAngle = 10f
)
)
// Stack Layout
setStackLayout(StackLayout.Linear)
setStackFrom(StackFrom.Bottom)
setTranslationInterval(16f)
// Swipe
setDirections(Direction.VERTICAL)
setManualRewindDirections(listOf(Direction.Left))
setSwipeThreshold(0.25f)
// Overlays
setOverlayInterpolator(AccelerateInterpolator())
// Animations
setLastItemAppearingAnimationDuration(200)
}- Performance: Don't change configurations too frequently at runtime
- UX: Inform users about changes (e.g., when swipes are disabled)
- Consistency: Use consistent configurations for similar features
- Testing: Test all configuration combinations thoroughly
- Configuration - All available options
- Basic Usage - Basic features
- Callbacks - Event handling