diff --git a/library/src/main/java/com/daimajia/swipe/SwipeLayout.java b/library/src/main/java/com/daimajia/swipe/SwipeLayout.java index d8ee9bde..13ccd883 100644 --- a/library/src/main/java/com/daimajia/swipe/SwipeLayout.java +++ b/library/src/main/java/com/daimajia/swipe/SwipeLayout.java @@ -8,6 +8,7 @@ import android.support.v4.view.ViewCompat; import android.support.v4.widget.ViewDragHelper; import android.util.AttributeSet; +import android.util.Log; import android.view.GestureDetector; import android.view.Gravity; import android.view.HapticFeedbackConstants; @@ -52,6 +53,7 @@ public class SwipeLayout extends FrameLayout { private List mSwipeDeniers = new ArrayList<>(); private Map> mRevealListeners = new HashMap<>(); private Map mShowEntirely = new HashMap<>(); + private Map mViewBoundCache = new HashMap<>();//save all children's bound, restore in onLayout private DoubleClickListener mDoubleClickListener; @@ -392,9 +394,35 @@ else if (mCurrentDragEdge == DragEdge.Bottom && newTop > getPaddingTop()) dispatchSwipeEvent(evLeft, evTop, dx, dy); invalidate(); + + captureChildrenBound(); } }; + /** + * save children's bounds, so they can restore the bound in {@link #onLayout(boolean, int, int, int, int)} + */ + private void captureChildrenBound(){ + View currentBottomView = getCurrentBottomView(); + if(getOpenStatus()==Status.Close){ + mViewBoundCache.remove(currentBottomView); + return; + } + + View[] views = new View[]{getSurfaceView(), currentBottomView}; + for (View child : views) { + Rect rect = mViewBoundCache.get(child); + if(rect==null){ + rect = new Rect(); + mViewBoundCache.put(child, rect); + } + rect.left = child.getLeft(); + rect.top = child.getTop(); + rect.right = child.getRight(); + rect.bottom = child.getBottom(); + } + } + /** * the dispatchRevealEvent method may not always get accurate position, it * makes the view may not always get the event when the view is totally @@ -763,30 +791,35 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) { } void layoutPullOut() { - Rect rect = computeSurfaceLayoutArea(false); View surfaceView = getSurfaceView(); + Rect surfaceRect = mViewBoundCache.get(surfaceView); + if(surfaceRect == null) surfaceRect = computeSurfaceLayoutArea(false); if (surfaceView != null) { - surfaceView.layout(rect.left, rect.top, rect.right, rect.bottom); + surfaceView.layout(surfaceRect.left, surfaceRect.top, surfaceRect.right, surfaceRect.bottom); bringChildToFront(surfaceView); } - rect = computeBottomLayoutAreaViaSurface(ShowMode.PullOut, rect); View currentBottomView = getCurrentBottomView(); + Rect bottomViewRect = mViewBoundCache.get(currentBottomView); + if(bottomViewRect == null) bottomViewRect = computeBottomLayoutAreaViaSurface(ShowMode.PullOut, surfaceRect); + Log.e("fax", this + ":bottomRect:"+bottomViewRect); if (currentBottomView != null) { - currentBottomView.layout(rect.left, rect.top, rect.right, rect.bottom); + currentBottomView.layout(bottomViewRect.left, bottomViewRect.top, bottomViewRect.right, bottomViewRect.bottom); } } void layoutLayDown() { - Rect rect = computeSurfaceLayoutArea(false); View surfaceView = getSurfaceView(); + Rect surfaceRect = mViewBoundCache.get(surfaceView); + if(surfaceRect == null) surfaceRect = computeSurfaceLayoutArea(false); if (surfaceView != null) { - surfaceView.layout(rect.left, rect.top, rect.right, rect.bottom); + surfaceView.layout(surfaceRect.left, surfaceRect.top, surfaceRect.right, surfaceRect.bottom); bringChildToFront(surfaceView); } - rect = computeBottomLayoutAreaViaSurface(ShowMode.LayDown, rect); View currentBottomView = getCurrentBottomView(); + Rect bottomViewRect = mViewBoundCache.get(currentBottomView); + if(bottomViewRect == null) bottomViewRect = computeBottomLayoutAreaViaSurface(ShowMode.LayDown, surfaceRect); if (currentBottomView != null) { - currentBottomView.layout(rect.left, rect.top, rect.right, rect.bottom); + currentBottomView.layout(bottomViewRect.left, bottomViewRect.top, bottomViewRect.right, bottomViewRect.bottom); } }