From 6c720620db6c2b9bc3b4a86f849e4d26cc09e8f7 Mon Sep 17 00:00:00 2001 From: huxq17 Date: Wed, 28 Sep 2016 17:31:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0xscrollview=E7=9A=84=E6=BB=91?= =?UTF-8?q?=E5=8A=A8=E7=9B=91=E5=90=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 ++- app/build.gradle | 2 +- .../com/andview/example/ScrollAdapter.java | 12 +++++++ .../example/activity/ScrollViewActivity.java | 1 + .../main/res/layout/adapter_scrollview.xml | 2 +- library/gradle.properties | 2 +- .../com/andview/refreshview/XScrollView.java | 32 +++++++++++++------ .../recyclerview/BaseRecyclerAdapter.java | 4 ++- 8 files changed, 46 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index ed88b75..ec8cf23 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ ```groovy dependencies { - compile 'com.huxq17.xrefreshview:xrefreshview:3.5.2' + compile 'com.huxq17.xrefreshview:xrefreshview:3.5.5' //依赖下面的库 compile 'com.android.support:recyclerview-v7:23.0.1' compile 'com.android.support:support-v4:23.0.1' @@ -31,6 +31,9 @@ dependencies { 还有listview,scrollview,webview等其他的view就不一一截图了。 ### 更新日志:
+ 2016-9-28: + 1.添加xscrollview的滑动监听 + 2016-9-6: 1.解决issue[#36](https://github.com/huxq17/XRefreshView/issues/36) diff --git a/app/build.gradle b/app/build.gradle index b9a6fe5..adc95eb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -25,7 +25,7 @@ android { dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') // compile project(':library') - compile 'com.huxq17.xrefreshview:xrefreshview:3.5.2' + compile 'com.huxq17.xrefreshview:xrefreshview:3.5.5' //依赖下面的库 compile 'com.android.support:recyclerview-v7:23.0.1' compile 'com.android.support:support-v4:23.0.1' diff --git a/app/src/main/java/com/andview/example/ScrollAdapter.java b/app/src/main/java/com/andview/example/ScrollAdapter.java index a81268d..afbe264 100644 --- a/app/src/main/java/com/andview/example/ScrollAdapter.java +++ b/app/src/main/java/com/andview/example/ScrollAdapter.java @@ -7,10 +7,12 @@ import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; +import android.widget.ScrollView; import android.widget.TextView; import com.andview.example.ui.raindrop.CustomerFooter; import com.andview.refreshview.XRefreshView; +import com.andview.refreshview.XScrollView; public class ScrollAdapter extends PagerAdapter { @@ -41,6 +43,16 @@ public int getCount() { public Object instantiateItem(ViewGroup view, int position) { final View imageLayout = mInflater.inflate(R.layout.adapter_scrollview, view, false); final XRefreshView outView = (XRefreshView) imageLayout.findViewById(R.id.custom_view); + final XScrollView scrollView = (XScrollView) imageLayout.findViewById(R.id.xscrollview); + scrollView.setOnScrollListener(new XScrollView.OnScrollListener() { + @Override + public void onScrollStateChanged(ScrollView view, int scrollState, boolean arriveBottom) { + } + + @Override + public void onScroll(int l, int t, int oldl, int oldt) { + } + }); outView.setAutoRefresh(false); outView.setPullLoadEnable(true); outView.setPinnedTime(1000); diff --git a/app/src/main/java/com/andview/example/activity/ScrollViewActivity.java b/app/src/main/java/com/andview/example/activity/ScrollViewActivity.java index d27be1f..bf24bb0 100644 --- a/app/src/main/java/com/andview/example/activity/ScrollViewActivity.java +++ b/app/src/main/java/com/andview/example/activity/ScrollViewActivity.java @@ -19,6 +19,7 @@ public void onCreate(Bundle savedInstanceState) { mViewPager = (ViewPager) findViewById(R.id.index_viewpager); ScrollAdapter adapter = new ScrollAdapter(this); mViewPager.setAdapter(adapter); + } @Override diff --git a/app/src/main/res/layout/adapter_scrollview.xml b/app/src/main/res/layout/adapter_scrollview.xml index 7ecf080..6952e52 100644 --- a/app/src/main/res/layout/adapter_scrollview.xml +++ b/app/src/main/res/layout/adapter_scrollview.xml @@ -8,7 +8,7 @@ xrefreshview:autoRefresh="false" > diff --git a/library/gradle.properties b/library/gradle.properties index 09ac54c..193d83c 100644 --- a/library/gradle.properties +++ b/library/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=3.5.2 +VERSION_NAME=3.5.5 GROUP=com.huxq17.xrefreshview POM_NAME=Android universal pull to refresh library POM_ARTIFACT_ID=xrefreshview diff --git a/library/src/main/java/com/andview/refreshview/XScrollView.java b/library/src/main/java/com/andview/refreshview/XScrollView.java index d710347..96d99a3 100644 --- a/library/src/main/java/com/andview/refreshview/XScrollView.java +++ b/library/src/main/java/com/andview/refreshview/XScrollView.java @@ -7,8 +7,7 @@ public class XScrollView extends ScrollView { - // 外部设置的监听方法 - private OnScrollListener onScrollListener; + private OnScrollListener onScrollListener, mScrollListener; // 是否在触摸状态 private boolean inTouch = false; // 上次滑动的最后位置 @@ -33,11 +32,17 @@ protected void onScrollChanged(int l, int t, int oldl, int oldt) { if (t != oldt) { // 有手指触摸,并且位置有滚动 onScrollListener.onScrollStateChanged(this, OnScrollListener.SCROLL_STATE_TOUCH_SCROLL, isBottom()); + if (mScrollListener != null) { + mScrollListener.onScrollStateChanged(this, OnScrollListener.SCROLL_STATE_TOUCH_SCROLL, isBottom()); + } } } else { if (t != oldt) { // 没有手指触摸,并且位置有滚动,就可以简单的认为是在fling onScrollListener.onScrollStateChanged(this, OnScrollListener.SCROLL_STATE_FLING, isBottom()); + if (mScrollListener != null) { + mScrollListener.onScrollStateChanged(this, OnScrollListener.SCROLL_STATE_FLING, isBottom()); + } // 记住上次滑动的最后位置 lastT = t; removeCallbacks(mRunnable); @@ -45,6 +50,9 @@ protected void onScrollChanged(int l, int t, int oldl, int oldt) { } } onScrollListener.onScroll(l, t, oldl, oldt); + if (mScrollListener != null) { + mScrollListener.onScroll(l, t, oldl, oldt); + } } private Runnable mRunnable = new Runnable() { @@ -53,6 +61,9 @@ public void run() { if (lastT == getScrollY() && !inTouch) { // 如果上次的位置和当前的位置相同,可认为是在空闲状态 onScrollListener.onScrollStateChanged(XScrollView.this, OnScrollListener.SCROLL_STATE_IDLE, isBottom()); + if (mScrollListener != null) { + mScrollListener.onScrollStateChanged(XScrollView.this, OnScrollListener.SCROLL_STATE_IDLE, isBottom()); + } } } }; @@ -62,14 +73,9 @@ private boolean isBottom() { } - /** - * 设置滚动监听事件 - * - * @param onScrollListener {@link OnScrollListener} 滚动监听事件(注意类的不同,虽然名字相同) - */ - public void setOnScrollListener(XRefreshView parent, OnScrollListener onScrollListener) { + protected void setOnScrollListener(XRefreshView parent, OnScrollListener scrollListener) { mParent = parent; - this.onScrollListener = onScrollListener; + this.onScrollListener = scrollListener; mParent.addTouchLifeCycle(new XRefreshView.TouchLifeCycle() { @Override public void onTouch(MotionEvent event) { @@ -91,6 +97,14 @@ public void onTouch(MotionEvent event) { }); } + /** + * 设置XScrollView的滚动监听 + * @param scrollListener + */ + public void setOnScrollListener(OnScrollListener scrollListener) { + mScrollListener = scrollListener; + } + /** * 滚动监听事件 */ diff --git a/library/src/main/java/com/andview/refreshview/recyclerview/BaseRecyclerAdapter.java b/library/src/main/java/com/andview/refreshview/recyclerview/BaseRecyclerAdapter.java index c97ef49..8fcd509 100644 --- a/library/src/main/java/com/andview/refreshview/recyclerview/BaseRecyclerAdapter.java +++ b/library/src/main/java/com/andview/refreshview/recyclerview/BaseRecyclerAdapter.java @@ -7,6 +7,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.ViewParent; import android.widget.FrameLayout; import com.andview.refreshview.XRefreshView; @@ -134,7 +135,8 @@ public void onViewAttachedToWindow(VH holder) { @Override public void onAttachedToRecyclerView(RecyclerView recyclerView) { super.onAttachedToRecyclerView(recyclerView); - if (recyclerView.getParent() instanceof XRefreshView) { + ViewParent parent = recyclerView.getParent(); + if (parent != null && parent instanceof XRefreshView) { mParent = (XRefreshView) recyclerView.getParent(); if (mParent != null && !observer.hasAttached()) { observer.setData(this, mParent);