diff --git a/README.md b/README.md index fdb8b98..1589964 100644 --- a/README.md +++ b/README.md @@ -33,32 +33,33 @@ Android拖拽布局,包括以下布局: com.mosect DragLayout - 1.0.2 + 1.0.3 pom ``` ## Gradle ``` -新版: -implementation 'com.mosect:DragLayout:1.0.2' +implementation 'com.mosect:DragLayout:1.0.3' implementation 'com.mosect:ViewUtils:1.0.5' - -旧版: -compile 'com.mosect:DragLayout:1.0.2' -compile 'com.mosect:ViewUtils:1.0.5' ``` # 更新记录 -## 1.0.1 -* 修复DragLayout canScrollHorizontally方法返回不正确问题(此问题会让包含DragLayout的ViewPager不能左滑) +## 1.0.3 +**此版为测试版,请谨慎更新** +* 修复上次滑动未完成,下次直接打开周边出现瞬间闪屏的问题 +* DragLayout直接继承ViewGroup,不继承FrameLayout +* 性能优化 +* 修复视图未加载时,调用openTop、openLeft、openRight、openBottom方法导致页面布局错乱问题 ## 1.0.2 * 优化滑动 * 移除ParentInterceptTouchHelper,改用ViewUtils库的InterceptTouchHelper +## 1.0.1 +* 修复DragLayout canScrollHorizontally方法返回不正确问题(此问题会让包含DragLayout的ViewPager不能左滑) # 其他: ``` -个人网站:http://www.mosect.com:5207 建设中…… +个人网站:http://www.mosect.com 建设中…… 邮箱:zhouliuyang1995@163.com QQ:905340954 ``` diff --git a/library/build.gradle b/library/build.gradle index 4a09738..a937957 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -6,7 +6,7 @@ publish { userOrg = 'mosect' // bintray.com用户名 groupId = 'com.mosect' // jcenter上的路径,bintray上创建Package时填写的Version control项 artifactId = 'DragLayout' // 项目名称,bintray上创建Package时填写的Name项 - publishVersion = '1.0.3-beta' // 版本号 + publishVersion = '1.0.3' // 版本号 desc = 'Android拖拽控件' // 描述,不重要 website = 'http://www.mosect.com' // 网站,最好有,不重要 } diff --git a/library/src/main/java/com/mosect/draglayout/lib/DragLayout.java b/library/src/main/java/com/mosect/draglayout/lib/DragLayout.java index d87a35c..0dea942 100644 --- a/library/src/main/java/com/mosect/draglayout/lib/DragLayout.java +++ b/library/src/main/java/com/mosect/draglayout/lib/DragLayout.java @@ -12,6 +12,7 @@ import android.view.VelocityTracker; import android.view.View; import android.view.ViewGroup; +import android.view.ViewTreeObserver; import android.widget.FrameLayout; import android.widget.Scroller; @@ -64,8 +65,8 @@ public class DragLayout extends ViewGroup { * 的速度,此速度默认为0,即关闭最大时间限制 */ private int maxScrollTime; - private boolean afterLayout; private LinkedList afterLayoutRunnableList; + private boolean attached = false; // 是否添加到窗口系统 private Rect outRect = new Rect(); // 辅助Gravity计算Rect private Rect containerRect = new Rect(); // 辅助Gravity计算Rect @@ -118,6 +119,16 @@ private void init(AttributeSet attrs) { gestureHelper = GestureHelper.createDefault(getContext()); layerScroller = new Scroller(getContext()); velocityTracker = VelocityTracker.obtain(); + getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + if (null != afterLayoutRunnableList && !afterLayoutRunnableList.isEmpty()) { + while (afterLayoutRunnableList.size() > 0) { + afterLayoutRunnableList.removeFirst().run(); + } + } + } + }); } @Override @@ -374,6 +385,9 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // 制作自己的测量规格,用于约束子视图 int smsw = MeasureUtils.makeSelfMeasureSpec(widthMeasureSpec, paddingWidth); int smsh = MeasureUtils.makeSelfMeasureSpec(heightMeasureSpec, paddingHeight); + // 制作自己的测量规格,不受padding影响,用于约束周边视图 + int smswnp = MeasureUtils.makeSelfMeasureSpec(widthMeasureSpec, 0); + int smshnp = MeasureUtils.makeSelfMeasureSpec(heightMeasureSpec, 0); // 内容的大小 int contentWidth = 0; int contentHeight = 0; @@ -386,8 +400,20 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int marginWidth = lp.leftMargin + lp.rightMargin; int marginHeight = lp.topMargin + lp.bottomMargin; // 制作子视图的测量规格 - int cmsw = MeasureUtils.makeChildMeasureSpec(smsw, lp.width, marginWidth); - int cmsh = MeasureUtils.makeChildMeasureSpec(smsh, lp.height, marginHeight); + int cmsw, cmsh; + switch (lp.layer) { + case LayoutParams.LAYER_LEFT: + case LayoutParams.LAYER_RIGHT: + case LayoutParams.LAYER_TOP: + case LayoutParams.LAYER_BOTTOM: + cmsw = MeasureUtils.makeChildMeasureSpec(smswnp, lp.width, marginWidth); + cmsh = MeasureUtils.makeChildMeasureSpec(smshnp, lp.height, marginHeight); + break; + default: + cmsw = MeasureUtils.makeChildMeasureSpec(smsw, lp.width, marginWidth); + cmsh = MeasureUtils.makeChildMeasureSpec(smsh, lp.height, marginHeight); + break; + } // 测量子视图 child.measure(cmsw, cmsh); // 子视图实际占用的大小(包括外边距) @@ -457,12 +483,6 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { onLayoutChildren(); - afterLayout = true; - if (null != afterLayoutRunnableList && !afterLayoutRunnableList.isEmpty()) { - while (afterLayoutRunnableList.size() > 0) { - afterLayoutRunnableList.removeFirst().run(); - } - } } /** @@ -566,7 +586,6 @@ public void layerScrollTo(int x, int y) { this.layerScrollX = x; this.layerScrollY = y; // System.out.println(String.format("layerScrollTo:x=%d,y=%d", x, y)); - // 重新布局 requestLayout(); // 触发对应方法 @@ -700,12 +719,18 @@ public boolean canScrollVertically(int direction) { return false; } + @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + attached = true; + } + @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); System.out.println("DragLayout:onDetachedFromWindow"); + attached = false; viewInfoCode = 0; - afterLayout = false; afterLayoutRunnableList = null; } @@ -1144,7 +1169,7 @@ public void run() { * @param runnable 任务 */ public void postAfterLayout(Runnable runnable) { - if (afterLayout) { + if (attached && !isLayoutRequested()) { runnable.run(); } else { if (null == afterLayoutRunnableList) {