From bdd59a1e2df81362b30d54be5ebd31492c2dc0c5 Mon Sep 17 00:00:00 2001 From: huangjian Date: Tue, 16 Nov 2021 13:07:34 +0800 Subject: [PATCH] =?UTF-8?q?DragLayout=E6=BB=91=E5=8A=A8=E5=86=B2=E7=AA=81?= =?UTF-8?q?=E8=A7=A3=E5=86=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yizhuan/erban/common/widget/DragLayout.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/yizhuan/erban/common/widget/DragLayout.java b/app/src/main/java/com/yizhuan/erban/common/widget/DragLayout.java index 8df3d0ad6..f34040a68 100644 --- a/app/src/main/java/com/yizhuan/erban/common/widget/DragLayout.java +++ b/app/src/main/java/com/yizhuan/erban/common/widget/DragLayout.java @@ -4,12 +4,10 @@ import android.content.Context; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.ViewGroup; -import android.view.ViewParent; import android.widget.FrameLayout; import android.widget.RelativeLayout; - /** * Created by huangmeng1 on 2018/3/7. * Updated by MadisonRong on 2018/4/23. @@ -54,6 +52,7 @@ public class DragLayout extends RelativeLayout { lastMoveY = lastY; break; case MotionEvent.ACTION_MOVE: + getParent().requestDisallowInterceptTouchEvent(true); dx = (int) event.getRawX() - lastX; dy = (int) event.getRawY() - lastY; @@ -106,19 +105,18 @@ public class DragLayout extends RelativeLayout { } private void reSetLayoutParams() { + ViewGroup.MarginLayoutParams layoutParams = null; if (getLayoutParams() instanceof RelativeLayout.LayoutParams) { - RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams( + layoutParams = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT ); - layoutParams.leftMargin = left; - layoutParams.topMargin = top; - layoutParams.width = getWidth(); - layoutParams.height = getHeight(); - setLayoutParams(layoutParams); } else if (getLayoutParams() instanceof FrameLayout.LayoutParams) { - FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams( + layoutParams = new FrameLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT ); + } + + if (layoutParams != null) { layoutParams.leftMargin = left; layoutParams.topMargin = top; layoutParams.width = getWidth(); @@ -137,6 +135,7 @@ public class DragLayout extends RelativeLayout { lastMoveY = lastY; break; case MotionEvent.ACTION_MOVE: + getParent().requestDisallowInterceptTouchEvent(true); dx = (int) event.getRawX() - lastX; dy = (int) event.getRawY() - lastY;