Skip to content

Commit

Permalink
优化细节 提供 scrollTop方法
Browse files Browse the repository at this point in the history
  • Loading branch information
haoxikang committed Aug 30, 2016
1 parent 6a47023 commit 0bc6a97
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected void onCreate(Bundle savedInstanceState) {
recyclerView = (RecyclerView) findViewById(R.id.recycler);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
final ScrollWebView scrollWebView = new ScrollWebView(this);
scrollWebView.loadUrl("https://app.4c.cn/web/details?nid=244&systemType=android&phoneName=E6683&phoneCode=33e129936a25fb1ac94f351e2fea6076");
scrollWebView.loadUrl("http://wap.4c.cn");
WebViewAdapter webViewAdapter = new WebViewAdapter(new MyAdapter(), scrollWebView);
webScrollLayout.setRecyclerviewScrollBottomListener(new WebScrollLayout.RecyclerviewScrollBottom() {
@Override
Expand All @@ -40,11 +40,8 @@ public void onScrollBottom() {
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
recyclerView.scrollToPosition(0);
scrollWebView.scrollTo(0, 0);
webScrollLayout.scrollTop();


// recyclerView.smoothScrollToPosition(20);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.ViewConfiguration;
import android.webkit.WebView;
import android.widget.LinearLayout;

Expand Down Expand Up @@ -90,10 +91,6 @@ public void onSChanged(int l, int t, int oldl, int oldt) {

}else {
System.out.println("WebView滑动到了不是底端");
if (isScrollUp && mDispatchWebView.isScroll()) {
mDispatchWebView.ignoreTouchCancel(true);
isIntercept = true;
}
}
}
});
Expand Down Expand Up @@ -144,11 +141,12 @@ public boolean dispatchTouchEvent(MotionEvent ev) {
case MotionEvent.ACTION_MOVE:

y2 = ev.getY();
if (y1 - y2 > 50) {
isScrollUp = true;
if (y1 - y2 >ViewConfiguration.get(getContext()).getScaledTouchSlop()) {
isScrollUp = true;

}
if (y2 - y1 > 50) {
if (y2 - y1 > ViewConfiguration.get(getContext()).getScaledTouchSlop()) {

isScrollUp = false;

}
Expand Down Expand Up @@ -201,4 +199,24 @@ public interface RecyclerviewScrollBottom {
void onScrollBottom();

}
public void scrollTop(){
if (recyclerView!=null&&mDispatchWebView!=null){
recyclerView.scrollToPosition(0);
mDispatchWebView.scrollTo(0, 0);
if (mDispatchWebView.isScroll()){
mDispatchWebView.ignoreTouchCancel(true);
isIntercept = true;
}
}

}

@Override
protected void onDetachedFromWindow() {
Log.d("销毁","销毁");
super.onDetachedFromWindow();
mDispatchWebView.destroy();
mDispatchWebView=null;
recyclerView=null;
}
}

0 comments on commit 0bc6a97

Please sign in to comment.