Skip to content

Commit

Permalink
修复、优化,更新readme说明
Browse files Browse the repository at this point in the history
  • Loading branch information
Mosect committed Jul 24, 2019
1 parent 9ec7181 commit b027525
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 23 deletions.
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,33 @@ Android拖拽布局,包括以下布局:
<dependency>
<groupId>com.mosect</groupId>
<artifactId>DragLayout</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>
<type>pom</type>
</dependency>
```

## 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
```
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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' // 网站,最好有,不重要
}
Expand Down
49 changes: 37 additions & 12 deletions library/src/main/java/com/mosect/draglayout/lib/DragLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -64,8 +65,8 @@ public class DragLayout extends ViewGroup {
* 的速度,此速度默认为0,即关闭最大时间限制
*/
private int maxScrollTime;
private boolean afterLayout;
private LinkedList<Runnable> afterLayoutRunnableList;
private boolean attached = false; // 是否添加到窗口系统

private Rect outRect = new Rect(); // 辅助Gravity计算Rect
private Rect containerRect = new Rect(); // 辅助Gravity计算Rect
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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);
// 子视图实际占用的大小(包括外边距)
Expand Down Expand Up @@ -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();
}
}
}

/**
Expand Down Expand Up @@ -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();

// 触发对应方法
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit b027525

Please sign in to comment.