diff --git a/README.md b/README.md
index 1241f30..0217a28 100644
--- a/README.md
+++ b/README.md
@@ -28,23 +28,15 @@ Android拖拽布局,包括以下布局:
# 使用:
项目已上传jcenter,可以直接使用maven或gradle引用本库。
-## Maven
-```
-
- com.mosect
- DragLayout
- 1.0.3
- pom
-
-```
-
## Gradle
```
-implementation 'com.mosect:DragLayout:1.0.3'
-implementation 'com.mosect:ViewUtils:1.0.5'
+implementation 'com.mosect:DragLayout:1.0.4'
```
# 更新记录
+## 1.0.4
+* 增加maxScrollTime(xml)
+* 增加touchScrollable属性,表示是否可以触摸滑动视图
## 1.0.3
* 修复上次滑动未完成,下次直接打开周边出现瞬间闪屏的问题
* DragLayout直接继承ViewGroup,不继承FrameLayout
diff --git a/example/src/main/java/com/mosect/draglayout/entity/ListItem.java b/example/src/main/java/com/mosect/draglayout/entity/ListItem.java
index 3a4b7c0..93e1945 100644
--- a/example/src/main/java/com/mosect/draglayout/entity/ListItem.java
+++ b/example/src/main/java/com/mosect/draglayout/entity/ListItem.java
@@ -6,6 +6,7 @@ public class ListItem implements Serializable, Cloneable {
private String title;
private String info;
+ private boolean touchScrollable; // 是否可以触摸滑动
@Override
public ListItem clone() {
@@ -31,4 +32,12 @@ public String getInfo() {
public void setInfo(String info) {
this.info = info;
}
+
+ public boolean isTouchScrollable() {
+ return touchScrollable;
+ }
+
+ public void setTouchScrollable(boolean touchScrollable) {
+ this.touchScrollable = touchScrollable;
+ }
}
diff --git a/example/src/main/java/com/mosect/draglayout/example/HorizontalDragListItemActivity.java b/example/src/main/java/com/mosect/draglayout/example/HorizontalDragListItemActivity.java
index bd11330..187b870 100644
--- a/example/src/main/java/com/mosect/draglayout/example/HorizontalDragListItemActivity.java
+++ b/example/src/main/java/com/mosect/draglayout/example/HorizontalDragListItemActivity.java
@@ -33,6 +33,7 @@ public void onClick(View v) {
ListItem item = new ListItem();
item.setTitle(getString(R.string.title) + (i + 1));
item.setInfo(getString(R.string.info));
+ item.setTouchScrollable(i % 2 == 0);
items.add(item);
}
adapter2.addAll(items);
diff --git a/example/src/main/java/com/mosect/draglayout/example/ListAdapter.java b/example/src/main/java/com/mosect/draglayout/example/ListAdapter.java
index d7a11e1..0cf11e2 100644
--- a/example/src/main/java/com/mosect/draglayout/example/ListAdapter.java
+++ b/example/src/main/java/com/mosect/draglayout/example/ListAdapter.java
@@ -19,7 +19,7 @@
public class ListAdapter extends RecyclerView.Adapter {
- private List data = new ArrayList<>();
+ protected List data = new ArrayList<>();
@NonNull
@Override
diff --git a/example/src/main/java/com/mosect/draglayout/example/ListAdapter2.java b/example/src/main/java/com/mosect/draglayout/example/ListAdapter2.java
index 10cb841..fea4ab2 100644
--- a/example/src/main/java/com/mosect/draglayout/example/ListAdapter2.java
+++ b/example/src/main/java/com/mosect/draglayout/example/ListAdapter2.java
@@ -40,6 +40,7 @@ public void onClick(View v) {
public void onBindViewHolder(@NonNull ItemHolder holder, int position) {
super.onBindViewHolder(holder, position);
DragLayout dragLayout = holder.itemView.findViewById(R.id.ly_drag);
+ dragLayout.setTouchScrollable(data.get(position).isTouchScrollable());
dragLayout.closeEdge(false); // 关闭周边
}
}
diff --git a/library/build.gradle b/library/build.gradle
index a937957..ee08a1b 100644
--- a/library/build.gradle
+++ b/library/build.gradle
@@ -6,8 +6,8 @@ publish {
userOrg = 'mosect' // bintray.com用户名
groupId = 'com.mosect' // jcenter上的路径,bintray上创建Package时填写的Version control项
artifactId = 'DragLayout' // 项目名称,bintray上创建Package时填写的Name项
- publishVersion = '1.0.3' // 版本号
- desc = 'Android拖拽控件' // 描述,不重要
+ publishVersion = '1.0.4' // 版本号
+ desc = 'DragLayout增加maxScrollTime(xml)和touchScrollable属性' // 描述,不重要
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 0dea942..826b772 100644
--- a/library/src/main/java/com/mosect/draglayout/lib/DragLayout.java
+++ b/library/src/main/java/com/mosect/draglayout/lib/DragLayout.java
@@ -65,6 +65,10 @@ public class DragLayout extends ViewGroup {
* 的速度,此速度默认为0,即关闭最大时间限制
*/
private int maxScrollTime;
+ /**
+ * 是否开启触摸滑动,默认开启
+ */
+ private boolean touchScrollable;
private LinkedList afterLayoutRunnableList;
private boolean attached = false; // 是否添加到窗口系统
@@ -109,11 +113,14 @@ public DragLayout(Context context, AttributeSet attrs, int defStyleAttr, int def
private void init(AttributeSet attrs) {
scrollVelocity = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
DEFAULT_SCROLL_VELOCITY_DP, getContext().getResources().getDisplayMetrics());
+ touchScrollable = true;
if (null != attrs) {
TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.DragLayout);
overScroll = ta.getInt(R.styleable.DragLayout_overScroll, OVER_SCROLL_ALL);
scrollVelocity = ta.getDimensionPixelSize(
R.styleable.DragLayout_scrollVelocity, scrollVelocity);
+ maxScrollTime = ta.getInt(R.styleable.DragLayout_maxScrollTime, 0);
+ touchScrollable = ta.getBoolean(R.styleable.DragLayout_touchScrollable, touchScrollable);
ta.recycle();
}
gestureHelper = GestureHelper.createDefault(getContext());
@@ -248,7 +255,9 @@ public boolean onTouchEvent(MotionEvent event) {
dy = getVerticalLayerScrollMax();
}
}
- layerScrollTo(getLayerScrollX(), dy);
+ if (touchScrollable) {
+ layerScrollTo(getLayerScrollX(), dy);
+ }
// 处理停止触摸情况
if (event.getAction() == MotionEvent.ACTION_UP ||
@@ -300,7 +309,9 @@ public boolean onTouchEvent(MotionEvent event) {
dx = getHorizontalLayerScrollMax();
}
}
- layerScrollTo(dx, getScrollY());
+ if (touchScrollable) {
+ layerScrollTo(dx, getScrollY());
+ }
// 处理停止触摸情况
if (event.getAction() == MotionEvent.ACTION_UP ||
@@ -490,7 +501,7 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
*/
protected void onLayoutChildren() {
// 布局子View
- System.out.println("onLayoutChildren==================");
+ // System.out.println("onLayoutChildren==================");
for (int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
if (child.getVisibility() == GONE) continue;
@@ -542,7 +553,7 @@ protected void onLayoutChildren() {
// 根据重力倾向,计算出视图位置
Gravity.apply(gravity, widthSpace, heightSpace, containerRect, outRect);
- System.out.println(String.format("Gravity.apply:%s,%s", containerRect, outRect));
+ // System.out.println(String.format("Gravity.apply:%s,%s", containerRect, outRect));
outRect.left += lp.leftMargin;
outRect.top += lp.topMargin;
outRect.right -= lp.rightMargin;
@@ -1202,14 +1213,47 @@ private void releaseTouch() {
}
}
+ /**
+ * 获取最大滑动时间
+ *
+ * @return 最大滑动时间
+ * @see #setMaxScrollTime(int)
+ */
public int getMaxScrollTime() {
return maxScrollTime;
}
+ /**
+ * 设置最大的滑动时间:如果smooth到目标位置需要的时间大于此时间,则以maxScrollTime时间到达目标
+ * 的速度滑动;如果此值小于等于0,不生效
+ *
+ * @param maxScrollTime 最大滑动时间
+ * @see #getMaxScrollTime()
+ */
public void setMaxScrollTime(int maxScrollTime) {
this.maxScrollTime = maxScrollTime;
}
+ /**
+ * 设置是否触摸滑动
+ *
+ * @param touchScrollable 是否开启触摸滑动:true,触摸导致视图进行滑动;false,触摸不会导致视图滑动
+ * @see #isTouchScrollable()
+ */
+ public void setTouchScrollable(boolean touchScrollable) {
+ this.touchScrollable = touchScrollable;
+ }
+
+ /**
+ * 判断是否开启触摸滑动
+ *
+ * @return true,触摸导致视图进行滑动;false,触摸不会导致视图滑动;默认为true
+ * @see #setTouchScrollable(boolean)
+ */
+ public boolean isTouchScrollable() {
+ return touchScrollable;
+ }
+
public static class LayoutParams extends MarginLayoutParams {
/**
diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml
index 17b0952..525a609 100644
--- a/library/src/main/res/values/attrs.xml
+++ b/library/src/main/res/values/attrs.xml
@@ -1,6 +1,7 @@
+
@@ -9,7 +10,12 @@
+
+
+
+
+