Skip to content

Commit 9db6325

Browse files
committed
change swip
1 parent 1b5cf37 commit 9db6325

2 files changed

Lines changed: 34 additions & 25 deletions

File tree

demo/src/main/AndroidManifest.xml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,32 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.uis.stackview.demo">
44

5+
<uses-permission android:name="android.permission.INTERNET" />
6+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
7+
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
8+
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
9+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
10+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
11+
512
<application
613
android:allowBackup="true"
714
android:hardwareAccelerated="true"
815
android:icon="@mipmap/ic_launcher"
916
android:label="@string/app_name"
10-
android:largeHeap="true"
1117
android:supportsRtl="true"
1218
android:theme="@style/AppTheme">
13-
<activity android:name=".activity.MainActivity">
19+
<activity android:name=".activity.MainActivity"
20+
android:screenOrientation="portrait"
21+
>
1422
<intent-filter>
1523
<action android:name="android.intent.action.MAIN" />
1624

1725
<category android:name="android.intent.category.LAUNCHER" />
1826
<action android:name="android.intent.action.VIEW"/>
1927
</intent-filter>
28+
2029
</activity>
2130
</application>
2231

2332

24-
<uses-permission android:name="android.permission.INTERNET" />
25-
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
26-
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
27-
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
28-
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
29-
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
30-
3133
</manifest>

library/src/main/java/com/uis/stackview/StackLayout.java

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import android.view.animation.DecelerateInterpolator;
1717
import android.view.animation.Interpolator;
1818
import android.widget.FrameLayout;
19+
import android.widget.Scroller;
1920

2021
import com.stone.pile.libs.R;
2122

@@ -29,6 +30,9 @@
2930

3031
public class StackLayout extends ViewGroup implements ViewTreeObserver.OnGlobalLayoutListener {
3132

33+
public final static int MODEL_LEFT = 1;
34+
public final static int MODEL_RIGHT = 2;
35+
3236
/** 层叠之间间距 */
3337
private int stackSpace = 30;
3438
/** 层叠视图边距 */
@@ -39,7 +43,8 @@ public class StackLayout extends ViewGroup implements ViewTreeObserver.OnGlobalL
3943
private int stackSize = 3;
4044
private boolean stackLooper = false;
4145
/** 1 ->left, 2 ->right */
42-
private int stackEdgeModel = 1;
46+
private int stackEdgeModel = MODEL_LEFT;
47+
4348

4449
private int everyWidth;
4550
private int everyHeight;
@@ -60,6 +65,7 @@ public class StackLayout extends ViewGroup implements ViewTreeObserver.OnGlobalL
6065
private FrameLayout animatingView;
6166
private VelocityTracker mVelocity;
6267

68+
6369
public StackLayout(Context context) {
6470
this(context, null);
6571
}
@@ -108,7 +114,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
108114
for(int i = 1; i < realSize; i++){
109115
originX.add(originX.get(i) + stackSpace);
110116
}
111-
originX.add(width-1);
117+
originX.add(width);
112118
}
113119
}
114120

@@ -120,7 +126,7 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
120126
itemView.measure(everyWidth, everyHeight);
121127
int x = originX.get(i);
122128
int left, right, pivot;
123-
if (stackEdgeModel == 1) {
129+
if (stackEdgeModel == MODEL_LEFT) {
124130
left = x;
125131
right = everyWidth + x;
126132
pivot = stackEdge;
@@ -245,7 +251,7 @@ public boolean onTouchEvent(MotionEvent event) {
245251
if(isSwipEnable(event)) {
246252
int currentX = (int) event.getX();
247253
int dx = (int) (currentX - lastX);
248-
requireScrollChange(dx);
254+
computeScroll(dx);
249255
lastX = currentX;
250256
}
251257
break;
@@ -276,7 +282,6 @@ private boolean isSwipEnable(MotionEvent event){
276282
return true;
277283
} else if (yDistance > xDistance && yDistance > mTouchSlop) {
278284
// 垂直滑动
279-
280285
}
281286
}
282287
return swipEnable;
@@ -289,21 +294,23 @@ private void requestParentDisallowInterceptTouchEvent(boolean disallowIntercept)
289294
}
290295
}
291296

292-
private void onRelease(float eventX, int velocityX) {
293-
294-
// animator = ObjectAnimator.ofFloat(this, "animateValue", animatingView.getLeft(), 0);
295-
// animator.setInterpolator(interpolator);
296-
// animator.setDuration(300).start();
297-
}
298-
299-
private void requireScrollChange(int dx) {
297+
public void computeScroll(int dx) {
300298
//dx<0 left, dx>0 right
301-
for (int i = 3,size = 1 + getRealStackSize(); i < size; i++) {
299+
for (int i = 3,size = 2 + getRealStackSize(); i < size; i++) {
302300
View itemView = getChildAt(i);
303-
itemView.offsetLeftAndRight(dx);
301+
itemView.setTranslationX(itemView.getTranslationX() + dx);
304302
}
305303
}
306304

305+
private void onRelease(float eventX, int velocityX) {
306+
307+
animator = ObjectAnimator.ofFloat(this, "animateValue", animatingView.getLeft(), 0);
308+
animator.setInterpolator(interpolator);
309+
animator.setDuration(300).start();
310+
}
311+
312+
313+
307314
private void initVelocityTracker() {
308315
if (mVelocity == null) {
309316
mVelocity = VelocityTracker.obtain();
@@ -321,7 +328,7 @@ public void setAnimateValue(float animateValue) {
321328
// 当前应该在的位置
322329
this.animateValue = animateValue;
323330
int dx = Math.round(animateValue - animatingView.getLeft());
324-
requireScrollChange(dx);
331+
computeScroll(dx);
325332
}
326333

327334
public float getAnimateValue() {

0 commit comments

Comments
 (0)