百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
C

CardStackView

> 编程语言
开源

适用于 Android 的类似 Tinder 的可滑动卡片视图

2.5K stars0 点赞0 次浏览
访问官网GitHub

工具介绍

适用于 Android 的类似 Tinder 的可滑动卡片视图

CardStackView

Overview

Contents

  • Setup
  • Features
    • Manual Swipe
    • Automatic Swipe
    • Cancel
    • Rewind
    • Overlay View
    • Overlay Interpolator
    • Paging
    • Reloading
    • Stack From
    • Visible Count
    • Translation Interval
    • Scale Interval
    • Swipe Threshold
    • Max Degree
    • Swipe Direction
    • Swipe Restriction
    • Swipeable Method
  • Public Interfaces
  • Callbacks
  • Migration Guide
  • Installation
  • License

Setup

kotlin
val cardStackView = findViewById<CardStackView>(R.id.card_stack_view)
cardStackView.layoutManager = CardStackLayoutManager()
cardStackView.adapter = CardStackAdapter()

Features

Manual Swipe

Automatic Swipe

kotlin
CardStackView.swipe()

You can set custom swipe animation.

kotlin
val setting = SwipeAnimationSetting.Builder()
        .setDirection(Direction.Right)
        .setDuration(Duration.Normal.duration)
        .setInterpolator(AccelerateInterpolator())
        .build()
CardStackLayoutManager.setSwipeAnimationSetting(setting)
CardStackView.swipe()

Cancel

Manual swipe is canceled when the card is dragged less than threshold.

Rewind

kotlin
CardStackView.rewind()

You can set custom rewind animation.

kotlin
val setting = RewindAnimationSetting.Builder()
        .setDirection(Direction.Bottom)
        .setDuration(Duration.Normal.duration)
        .setInterpolator(DecelerateInterpolator())
        .build()
CardStackLayoutManager.setRewindAnimationSetting(setting)
CardStackView.rewind()

Overlay View

Value Sample
Left
Right

Put overlay view in your item layout of RecyclerView.

xml
<FrameLayout
    android:id="@+id/left_overlay"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    

</FrameLayout>
Value Layout ID
Left left_overlay
Right right_overlay
Top top_overlay
Bottom bottom_overlay

Overlay Interpolator

You can set own interpolator to define the rate of change of alpha.

kotlin
CardStackLayoutManager.setOverlayInterpolator(LinearInterpolator())

Paging

You can implement paging by using following two ways.

  1. Use DiffUtil.
  2. Call RecyclerView.Adapter.notifyItemRangeInserted manually.

Caution

You should NOT call RecyclerView.Adapter.notifyDataSetChanged for paging because this method will reset top position and maybe occur a perfomance issue.

Reloading

You can implement reloading by calling RecyclerView.Adapter.notifyDataSetChanged.

Stack From

Default Value Sample
✅ None
Top
Bottom
Left
Right
kotlin
CardStackLayoutManager.setStackFrom(StackFrom.None)

Visible Count

Default Value Sample
2
✅ 3
4
kotlin
CardStackLayoutManager.setVisibleCount(3)

Translation Interval

Default Value Sample
4dp
✅ 8dp
12dp
kotlin
CardStackLayoutManager.setTranslationInterval(8.0f)

Scale Interval

Default Value Sample
✅ 95%
90%
kotlin
CardStackLayoutManager.setScaleInterval(0.95f)

Max Degree

Default Value Sample
✅ 20°
0°
kotlin
CardStackLayoutManager.setMaxDegree(20.0f)

Swipe Direction

Default Value Sample
✅ Horizontal
Vertical
Freedom
kotlin
CardStackLayoutManager.setDirections(Direction.HORIZONTAL)

Swipe Threshold

Default Value Sample
✅ 30%
10%
kotlin
CardStackLayoutManager.setSwipeThreshold(0.3f)

Swipe Restriction

CanScrollHorizontal CanScrollVertical Sample
true true
true false
false true
false false
kotlin
CardStackLayoutManager.setCanScrollHorizontal(true)
CardStackLayoutManager.setCanScrollVertical(true)

Swipeable Method

Default Value Sample
✅ AutomaticAndManual
Automatic
Manual
None
kotlin
CardStackLayoutManager.setSwipeableMethod(SwipeableMethod.AutomaticAndManual)

Public Interfaces

Basic usages

Method Description
CardStackView.swipe() You can swipe once by calling this method.
CardStackView.rewind() You can rewind once by calling this method.
CardStackLayoutManager.getTopPosition() You can get position displayed on top.
CardStackLayoutManager.setStackFrom(StackFrom stackFrom) You can set StackFrom.
CardStackLayoutManager.setTranslationInterval(float translationInterval) You can set TranslationInterval.
CardStackLayoutManager.setScaleInterval(float scaleInterval) You can set ScaleInterval.
CardStackLayoutManager.setSwipeThreshold(float swipeThreshold) You can set SwipeThreshold.
CardStackLayoutManager.setMaxDegree(float maxDegree) You can set MaxDegree.
CardStackLayoutManager.setDirections(List directions) You can set Direction.
CardStackLayoutManager.setCanScrollHorizontal(boolean canScrollHorizontal) You can set CanScrollHorizontal.
CardStackLayoutManager.setCanScrollVertical(boolean canScrollVertical) You can set CanScrollVertical.
CardStackLayoutManager.setSwipeAnimationSetting(SwipeAnimationSetting swipeAnimationSetting) You can set SwipeAnimationSetting.
CardStackLayoutManager.setRewindAnimationSetting(RewindAnimationSetting rewindAnimationSetting) You can set RewindAnimationSetting.

Advanced usages

Method Description
CardStackView.smoothScrollToPosition(int position) You can scroll any position with animation.
CardStackView.scrollToPosition(int position) You can scroll any position without animation.

Callbacks

Method Description
CardStackListener.onCardDragging(Direction direction, float ratio) This method is called while the card is dragging.
CardStackListener.onCardSwiped(Direction direction) This method is called when the card is swiped.
CardStackListener.onCardRewound() This method is called when the card is rewinded.
CardStackListener.onCardCanceled() This method is called when the card is dragged less than threshold.
CardStackListener.onCardAppeared(View view, int position) This method is called when the card appeared.
CardStackListener.onCardDisappeared(View view, int position) This method is called when the card disappeared.

Migration Guide

Migration of Features

1.x 2.x
Move to Origin Cancel
Reverse Rewind
ElevationEnabled Stack From
TranslationDiff Translation Interval
ScaleDiff Scale Interval
SwipeEnabled Swipe Restriction

Migration of Callbacks

1.x 2.x
CardStackView.CardEventListener CardStackListener
onCardDragging(float percentX, float percentY) onCardDragging(Direction direction, float ratio)
onCardSwiped(SwipeDirection direction) onCardSwiped(Direction direction)
onCardReversed() onCardRewound()
onCardMovedToOrigin() onCardCanceled()
onCardClicked(int index) This method is no longer provided. Please implement in your item of RecyclerView.

Installation

groovy
dependencies {
    implementation "com.yuyakaido.android:card-stack-view:2.3.4"
}

License

Copyright 2018 yuyakaido

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Javaandroidlayoutmanagerrecyclerviewtinder

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言