Skip to content

Commit 689e41c

Browse files
committed
Added feature to set ScaleDiff
1 parent e594b93 commit 689e41c

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

cardstackview/src/main/java/com/yuyakaido/android/cardstackview/CardStackView.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public CardStackView(Context context, AttributeSet attrs, int defStyle) {
9292
setVisibleCount(array.getInt(R.styleable.CardStackView_visibleCount, option.visibleCount));
9393
setSwipeThreshold(array.getFloat(R.styleable.CardStackView_swipeThreshold, option.swipeThreshold));
9494
setTranslationDiff(array.getFloat(R.styleable.CardStackView_translationDiff, option.translationDiff));
95+
setScaleDiff(array.getFloat(R.styleable.CardStackView_scaleDiff, option.scaleDiff));
9596
setStackFrom(StackFrom.values()[array.getInt(R.styleable.CardStackView_stackFrom, option.stackFrom.ordinal())]);
9697
setElevationEnabled(array.getBoolean(R.styleable.CardStackView_elevationEnabled, option.isElevationEnabled));
9798
setSwipeEnabled(array.getBoolean(R.styleable.CardStackView_swipeEnabled, option.isSwipeEnabled));
@@ -205,8 +206,8 @@ private void update(float percentX, float percentY) {
205206
for (int i = 1; i < option.visibleCount; i++) {
206207
CardContainerView view = containers.get(i);
207208

208-
float currentScale = 1f - (i * 0.02f);
209-
float nextScale = 1f - ((i - 1) * 0.02f);
209+
float currentScale = 1f - (i * option.scaleDiff);
210+
float nextScale = 1f - ((i - 1) * option.scaleDiff);
210211
float percent = currentScale + (nextScale - currentScale) * Math.abs(percentX);
211212
ViewCompat.setScaleX(view, percent);
212213
ViewCompat.setScaleY(view, percent);
@@ -371,6 +372,13 @@ public void setTranslationDiff(float translationDiff) {
371372
}
372373
}
373374

375+
public void setScaleDiff(float scaleDiff) {
376+
option.scaleDiff = scaleDiff;
377+
if (adapter != null) {
378+
initialize(false);
379+
}
380+
}
381+
374382
public void setStackFrom(StackFrom stackFrom) {
375383
option.stackFrom = stackFrom;
376384
if (adapter != null) {

cardstackview/src/main/java/com/yuyakaido/android/cardstackview/internal/CardStackOption.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77

88
public class CardStackOption {
99
public int visibleCount = 3;
10-
public float swipeThreshold = 0.75f;
10+
public float swipeThreshold = 0.75f; // Percentage
1111
public float translationDiff = 12f; // DP
12+
public float scaleDiff = 0.02f; // Percentage
1213
public StackFrom stackFrom = StackFrom.DEFAULT;
1314
public boolean isElevationEnabled = true;
1415
public boolean isSwipeEnabled = true;
15-
public int leftOverlay = 0;
16-
public int rightOverlay = 0;
16+
public int leftOverlay = 0; // Layout Resource ID
17+
public int rightOverlay = 0; // Layout Resource ID
1718
public List<SwipeDirection> swipeDirection = SwipeDirection.FREEDOM;
1819
}

cardstackview/src/main/res/values/attrs.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<attr name="visibleCount" format="integer"/>
66
<attr name="swipeThreshold" format="float"/>
77
<attr name="translationDiff" format="float"/>
8+
<attr name="scaleDiff" format="float"/>
89
<attr name="stackFrom" format="enum">
910
<enum name="bottom" value="0"/>
1011
<enum name="top" value="1"/>

sample/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
app:visibleCount="3"
1919
app:swipeThreshold="0.75"
2020
app:translationDiff="12"
21+
app:scaleDiff="0.02"
2122
app:stackFrom="top"
2223
app:elevationEnabled="true"
2324
app:swipeEnabled="true"

0 commit comments

Comments
 (0)