This repository is a fork of CardStackView. I fixed some bugs, updated the dependencies and gradle, and converted the code to Kotlin. In addition, in the changelogs you can see all other features I added.
-
Include the library as a local library project in your build.gradle:
allprojects { repositories { ... maven { url 'https://jitpack.io' } } } ... dependencies { implementation 'com.github.jens-muenker:CardStackView:3.0.0' }
-
Add a CardStackView to your layout
<com.yuyakaido.android.cardstackview.CardStackView android:id="@+id/card_stack_view" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" />
-
Implement an adapter for your stack view. This should be a (RecyclerView.Adapter). There is a Sample CardStackAdapter in this project. You may also want to use a ListAdapter for less boilerplate code, and automatically handled range updates (especially helpful if your data updates as the user interacts).
-
Wire up your view with your Adapter:
val cardStackView = findViewById<CardStackView>(R.id.card_stack_view) cardStackView.layoutManager = CardStackLayoutManager() cardStackView.adapter = CardStackAdapter()
CardStackView.swipe()
You can set custom swipe animation.
val setting = SwipeAnimationSetting.Builder()
.setDirection(Direction.Right)
.setDuration(Duration.Normal.duration)
.setInterpolator(AccelerateInterpolator())
.build()
CardStackLayoutManager.setSwipeAnimationSetting(setting)
CardStackView.swipe()
Manual swipe is canceled when the card is dragged less than threshold.
CardStackView.rewind()
You can set custom rewind animation.
val setting = RewindAnimationSetting.Builder()
.setDirection(Direction.Bottom)
.setDuration(Duration.Normal.duration)
.setInterpolator(DecelerateInterpolator())
.build()
CardStackLayoutManager.setRewindAnimationSetting(setting)
CardStackView.rewind()
Value | Sample |
---|---|
Left | |
Right |
Put overlay view in your item layout of RecyclerView.
<FrameLayout
android:id="@+id/left_overlay"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Set your left overlay -->
</FrameLayout>
Value | Layout ID |
---|---|
Left | left_overlay |
Right | right_overlay |
Top | top_overlay |
Bottom | bottom_overlay |
You can set own interpolator to define the rate of change of alpha.
CardStackLayoutManager.setOverlayInterpolator(LinearInterpolator())
You can implement paging by using following two ways.
- Use DiffUtil.
- 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.
You can implement reloading by calling RecyclerView.Adapter.notifyDataSetChanged
.
Default | Value | Sample |
---|---|---|
✅ | None | |
Top | ||
Bottom | ||
Left | ||
Right |
CardStackLayoutManager.setStackFrom(StackFrom.None)
Default | Value | Sample |
---|---|---|
2 | ||
✅ | 3 | |
4 |
CardStackLayoutManager.setVisibleCount(3)
Default | Value | Sample |
---|---|---|
4dp | ||
✅ | 8dp | |
12dp |
CardStackLayoutManager.setTranslationInterval(8.0f)
Default | Value | Sample |
---|---|---|
✅ | 95% | |
90% |
CardStackLayoutManager.setScaleInterval(0.95f)
Default | Value | Sample |
---|---|---|
✅ | 20° | |
0° |
CardStackLayoutManager.setMaxDegree(20.0f)
Default | Value | Sample |
---|---|---|
✅ | Horizontal | |
Vertical | ||
Freedom |
CardStackLayoutManager.setDirections(Direction.HORIZONTAL)
Default | Value | Sample |
---|---|---|
✅ | 30% | |
10% |
CardStackLayoutManager.setSwipeThreshold(0.3f)
CanScrollHorizontal | CanScrollVertical | Sample |
---|---|---|
true | true | |
true | false | |
false | true | |
false | false |
CardStackLayoutManager.setCanScrollHorizontal(true)
CardStackLayoutManager.setCanScrollVertical(true)
Default | Value | Sample |
---|---|---|
✅ | AutomaticAndManual | |
Automatic | ||
Manual | ||
None |
CardStackLayoutManager.setSwipeableMethod(SwipeableMethod.AutomaticAndManual)
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. |
Method | Description |
---|---|
CardStackView.smoothScrollToPosition(int position) | You can scroll any position with animation. |
CardStackView.scrollToPosition(int position) | You can scroll any position without animation. |
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. |
3.0.0
- updated to newest gradle version
- updated libraries to newest versions
- translated code to kotlin
This software is licensed under the Apache License, Version 2.0. See the LICENSE file for details.
Copyright 2024, Jens Münker
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.
For CardStackView:
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.