Skip to content

Commit 5993aac

Browse files
committed
发布一个新版本
1 parent c1aee94 commit 5993aac

File tree

5 files changed

+63
-12
lines changed

5 files changed

+63
-12
lines changed

.idea/misc.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/com/example/administrator/webviewlist/MainActivity.java

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.os.Bundle;
55
import android.support.v7.widget.LinearLayoutManager;
66
import android.support.v7.widget.RecyclerView;
7+
import android.util.Log;
78

89
import com.example.webviewscroll.WebScrollLayout;
910
import com.example.webviewscroll.WebViewAdapter;
@@ -21,6 +22,12 @@ protected void onCreate(Bundle savedInstanceState) {
2122
linearLayoutManager = new LinearLayoutManager(this);
2223
recyclerView.setLayoutManager(linearLayoutManager);
2324
WebViewAdapter webViewAdapter = new WebViewAdapter(new MyAdapter(),"http://wap.4c.cn");
25+
webScrollLayout.setRecyclerviewScrollBottomListener(new WebScrollLayout.RecyclerviewScrollBottom() {
26+
@Override
27+
public void onScrollBottom() {
28+
Log.d("测试","滑动到底部");
29+
}
30+
});
2431
webViewAdapter.attchLayout(webScrollLayout);
2532
recyclerView.setAdapter(webViewAdapter);
2633

webviewscroll/src/main/java/com/example/webviewscroll/ScrollWebView.java

+18-11
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
public class ScrollWebView extends WebView {
1616
boolean mIgnoreTouchCancel;
1717
public ScrollInterface mScrollInterface;
18-
private boolean isScroll=true;
18+
private boolean isScroll = true;
1919
private int maxH;
20+
2021
public ScrollWebView(Context context) {
2122
super(context);
2223
}
@@ -33,9 +34,11 @@ public ScrollWebView(Context context, AttributeSet attrs, int defStyleAttr) {
3334
public ScrollWebView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
3435
super(context, attrs, defStyleAttr, defStyleRes);
3536
}
36-
public void ignoreTouchCancel (boolean val) {
37+
38+
public void ignoreTouchCancel(boolean val) {
3739
mIgnoreTouchCancel = val;
3840
}
41+
3942
@Override
4043
public boolean onTouchEvent(MotionEvent ev) {
4144
int action = ev.getAction();
@@ -50,20 +53,23 @@ public boolean onTouchEvent(MotionEvent ev) {
5053
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
5154

5255
super.onScrollChanged(l, t, oldl, oldt);
53-
mScrollInterface.onSChanged(l, t, oldl, oldt);
56+
if (mScrollInterface!=null){
57+
mScrollInterface.onSChanged(l, t, oldl, oldt);
58+
59+
}
5460

5561
}
5662

5763
@Override
5864
protected void onSizeChanged(int w, int h, int ow, int oh) {
59-
if (h>maxH){
65+
if (h > maxH) {
6066
ViewGroup.LayoutParams layoutParams = getLayoutParams();
61-
layoutParams.height=maxH;
67+
layoutParams.height = maxH;
6268
setLayoutParams(layoutParams);
63-
isScroll=true;
69+
isScroll = true;
6470
}
65-
if (h<maxH){
66-
isScroll=false;
71+
if (h < maxH) {
72+
isScroll = false;
6773
}
6874
super.onSizeChanged(w, h, ow, oh);
6975
}
@@ -79,9 +85,10 @@ public interface ScrollInterface {
7985
public void onSChanged(int l, int t, int oldl, int oldt);
8086

8187
}
82-
public void setMaxH(int h){
83-
maxH=h;
84-
}
88+
89+
public void setMaxH(int h) {
90+
maxH = h;
91+
}
8592

8693
public boolean isScroll() {
8794
return isScroll;

webviewscroll/src/main/java/com/example/webviewscroll/WebScrollLayout.java

+31
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class WebScrollLayout extends LinearLayout {
1717
private ScrollWebView mDispatchWebView;
1818
float y1 = 0;
1919
float y2 = 0;
20+
public RecyclerviewScrollBottom recyclerviewScrollBottomListener;
2021
private boolean isIntercept = false;
2122
boolean isScrollUp = true;
2223
private RecyclerView recyclerView;
@@ -26,6 +27,8 @@ public void preventParentTouchEvent(WebView view) {
2627
if (getChildAt(0) != null) {
2728
recyclerView = (RecyclerView) getChildAt(0);
2829
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
30+
boolean isSlidingToLast = false;
31+
2932
@Override
3033
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
3134
LinearLayoutManager manager = (LinearLayoutManager) recyclerView.getLayoutManager();
@@ -35,11 +38,30 @@ public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
3538
} else {
3639
onScrollTop(false);
3740
}
41+
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
42+
int count = recyclerView.getAdapter().getItemCount();
43+
//获取最后一个完全显示的ItemPosition
44+
int lastVisibleItem = manager.findLastCompletelyVisibleItemPosition();
45+
int totalItemCount = manager.getItemCount();
46+
47+
// 判断是否滚动到底部,并且是向右滚动
48+
if (lastVisibleItem == (totalItemCount - 1) && isSlidingToLast) {
49+
recyclerviewScrollBottomListener.onScrollBottom();
50+
}
51+
}
3852
}
3953

4054
@Override
4155
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
4256
super.onScrolled(recyclerView, dx, dy);
57+
//dx用来判断横向滑动方向,dy用来判断纵向滑动方向
58+
if (dy > 0) {
59+
//大于0表示,正在向右滚动
60+
isSlidingToLast = true;
61+
} else {
62+
//小于等于0 表示停止或向左滚动
63+
isSlidingToLast = false;
64+
}
4365

4466

4567
}
@@ -158,5 +180,14 @@ private void onScrollTop(boolean istop) { //recyclerview是否滑动到顶部
158180
}
159181
}
160182
}
183+
public void setRecyclerviewScrollBottomListener(RecyclerviewScrollBottom recyclerviewScrollBottomListener) {
161184

185+
this.recyclerviewScrollBottomListener = recyclerviewScrollBottomListener;
186+
187+
}
188+
public interface RecyclerviewScrollBottom {
189+
190+
public void onScrollBottom();
191+
192+
}
162193
}

0 commit comments

Comments
 (0)