Skip to content

Commit 06c46eb

Browse files
authored
Merge pull request yuyakaido#17 from yuyakaido/scale-diff
Added feature to set ScaleDiff
2 parents e594b93 + e5007c1 commit 06c46eb

File tree

7 files changed

+35
-5
lines changed

7 files changed

+35
-5
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
- [VisibleCount](#visiblecount)
2222
- [ElevationEnabled](#elevationenabled)
2323
- [TranslationDiff](#translationdiff)
24+
- [ScaleDiff](#scalediff)
2425
- [Overlay](#overlay)
2526
- [SwipeEnabled](#swipeenabled)
2627
- [SwipeDirection](#swipedirection)
@@ -135,6 +136,24 @@ The unit of TranslationDiff is **dp**.
135136
CardStackView#setTranslationDiff(12f);
136137
```
137138

139+
## ScaleDiff
140+
141+
The range of ScaleDiff is 0.0 - 1.0.
142+
143+
| Default | Value | Sample |
144+
| :----: | :----: | :----: |
145+
|| 0.02 | ![ScaleDiff-2](https://github.com/yuyakaido/CardStackView/blob/master/images/scale-diff-2.png) |
146+
| | 0.1 | ![ScaleDiff-10](https://github.com/yuyakaido/CardStackView/blob/master/images/scale-diff-10.png) |
147+
148+
```xml
149+
<com.yuyakaido.android.cardstackview.CardStackView
150+
app:scaleDiff="0.02"/>
151+
```
152+
153+
```java
154+
CardStackView#setScaleDiff(0.02f);
155+
```
156+
138157
## Overlay
139158

140159
| Value | Sample |

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"/>

images/scale-diff-10.png

23.1 KB
Loading

images/scale-diff-2.png

24.3 KB
Loading

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)