diff --git a/examples/src/main/java/com/alibaba/android/vlayout/example/VLayoutActivity.java b/examples/src/main/java/com/alibaba/android/vlayout/example/VLayoutActivity.java index 318f3195..dca43f00 100644 --- a/examples/src/main/java/com/alibaba/android/vlayout/example/VLayoutActivity.java +++ b/examples/src/main/java/com/alibaba/android/vlayout/example/VLayoutActivity.java @@ -29,6 +29,7 @@ import com.alibaba.android.vlayout.RecyclablePagerAdapter; import com.alibaba.android.vlayout.VirtualLayoutManager; import com.alibaba.android.vlayout.VirtualLayoutManager.LayoutParams; +import com.alibaba.android.vlayout.extend.LayoutManagerCanScrollListener; import com.alibaba.android.vlayout.extend.PerformanceMonitor; import com.alibaba.android.vlayout.extend.ViewLifeCycleListener; import com.alibaba.android.vlayout.layout.ColumnLayoutHelper; @@ -197,6 +198,20 @@ public void onDisappeared(View view) { } }); + layoutManager.setLayoutManagerCanScrollListener(new LayoutManagerCanScrollListener() { + @Override + public boolean canScrollVertically() { + Log.i("vlayout", "canScrollVertically: "); + return true; + } + + @Override + public boolean canScrollHorizontally() { + Log.i("vlayout", "canScrollHorizontally: "); + return true; + } + }); + final DelegateAdapter delegateAdapter = new DelegateAdapter(layoutManager, true); recyclerView.setAdapter(delegateAdapter); diff --git a/vlayout/src/main/java/com/alibaba/android/vlayout/VirtualLayoutManager.java b/vlayout/src/main/java/com/alibaba/android/vlayout/VirtualLayoutManager.java index 96db6593..257d960c 100644 --- a/vlayout/src/main/java/com/alibaba/android/vlayout/VirtualLayoutManager.java +++ b/vlayout/src/main/java/com/alibaba/android/vlayout/VirtualLayoutManager.java @@ -39,6 +39,7 @@ import android.view.ViewGroup; import android.view.ViewParent; +import com.alibaba.android.vlayout.extend.LayoutManagerCanScrollListener; import com.alibaba.android.vlayout.extend.PerformanceMonitor; import com.alibaba.android.vlayout.extend.ViewLifeCycleHelper; import com.alibaba.android.vlayout.extend.ViewLifeCycleListener; @@ -100,6 +101,8 @@ public static void enableDebugging(boolean isDebug) { private boolean mCanScrollVertically; + private LayoutManagerCanScrollListener layoutManagerCanScrollListener; + private boolean mEnableMarginOverlapping = false; private int mMaxMeasureSize = -1; @@ -169,6 +172,10 @@ public void setCanScrollHorizontally(boolean canScrollHorizontally) { this.mCanScrollHorizontally = canScrollHorizontally; } + public void setLayoutManagerCanScrollListener(LayoutManagerCanScrollListener layoutManagerCanScrollListener) { + this.layoutManagerCanScrollListener = layoutManagerCanScrollListener; + } + public void setNestedScrolling(boolean nestedScrolling) { setNestedScrolling(nestedScrolling, -1); } @@ -1327,12 +1334,20 @@ public int getChildMeasureSpec(int parentSize, int size, boolean canScroll) { @Override public boolean canScrollHorizontally() { - return mCanScrollHorizontally && !mNoScrolling; + boolean ret = true; + if (layoutManagerCanScrollListener != null) { + ret = ret && layoutManagerCanScrollListener.canScrollHorizontally(); + } + return mCanScrollHorizontally && !mNoScrolling && ret; } @Override public boolean canScrollVertically() { - return mCanScrollVertically && !mNoScrolling; + boolean ret = true; + if (layoutManagerCanScrollListener != null) { + ret = ret && layoutManagerCanScrollListener.canScrollVertically(); + } + return mCanScrollVertically && !mNoScrolling && ret; } @Override diff --git a/vlayout/src/main/java/com/alibaba/android/vlayout/extend/LayoutManagerCanScrollListener.java b/vlayout/src/main/java/com/alibaba/android/vlayout/extend/LayoutManagerCanScrollListener.java new file mode 100644 index 00000000..01d3b011 --- /dev/null +++ b/vlayout/src/main/java/com/alibaba/android/vlayout/extend/LayoutManagerCanScrollListener.java @@ -0,0 +1,7 @@ +package com.alibaba.android.vlayout.extend; + +public interface LayoutManagerCanScrollListener { + boolean canScrollVertically(); + + boolean canScrollHorizontally(); +}