Skip to content

Commit 8f84c60

Browse files
committed
fix(layer-core): 优化SwipeLayout
1 parent 9d37d04 commit 8f84c60

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

layer-core/src/main/java/per/goweii/layer/core/widget/SwipeLayout.java

+28-1
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,42 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
174174

175175
@Override
176176
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
177-
super.onLayout(changed, left, top, right, bottom);
178177
if (getChildCount() != 1) {
179178
throw new IllegalStateException("只能设置一个子View");
180179
}
180+
super.onLayout(changed, left, top, right, bottom);
181181
mSwipeView = getChildAt(0);
182182
mLeft = mSwipeView.getLeft();
183183
mTop = mSwipeView.getTop();
184184
mRight = mSwipeView.getRight();
185185
mBottom = mSwipeView.getBottom();
186+
187+
if (mSwipeFraction != 0) {
188+
int offx = 0;
189+
int offy = 0;
190+
switch (mCurrSwipeDirection) {
191+
case Direction.LEFT:
192+
offx = -(int) (mSwipeFraction * calcViewLeftRange(mSwipeView));
193+
break;
194+
case Direction.RIGHT:
195+
offx = (int) (mSwipeFraction * calcViewRightRange(mSwipeView));
196+
break;
197+
case Direction.TOP:
198+
offy = -(int) (mSwipeFraction * calcViewTopRange(mSwipeView));
199+
break;
200+
case Direction.BOTTOM:
201+
offy = (int) (mSwipeFraction * calcViewBottomRange(mSwipeView));
202+
break;
203+
default:
204+
break;
205+
}
206+
if (offx != 0) {
207+
mSwipeView.offsetLeftAndRight(offx);
208+
}
209+
if (offy != 0) {
210+
mSwipeView.offsetTopAndBottom(offy);
211+
}
212+
}
186213
}
187214

188215
public int getSwipeX() {

0 commit comments

Comments
 (0)