Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: haoxikang/WebViewList
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.1.7
Choose a base ref
...
head repository: haoxikang/WebViewList
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref

Commits on Aug 25, 2016

  1. 修改

    haoxikang committed Aug 25, 2016
    Copy the full SHA
    a979932 View commit details
  2. 修改

    haoxikang committed Aug 25, 2016
    Copy the full SHA
    e46afd8 View commit details

Commits on Aug 26, 2016

  1. 正式版本

    haoxikang committed Aug 26, 2016
    Copy the full SHA
    0a1d341 View commit details
  2. Add files via upload

    haoxikang authored Aug 26, 2016
    Copy the full SHA
    d29a53d View commit details
  3. Update README.md

    haoxikang authored Aug 26, 2016
    Copy the full SHA
    d7843c7 View commit details
  4. Update README.md

    haoxikang authored Aug 26, 2016
    Copy the full SHA
    2577f7d View commit details
  5. Update README.md

    haoxikang authored Aug 26, 2016
    Copy the full SHA
    0f6d5c5 View commit details

Commits on Aug 29, 2016

  1. 分离了Webview

    haoxikang committed Aug 29, 2016
    Copy the full SHA
    a2d80b6 View commit details
  2. Copy the full SHA
    9409cb0 View commit details
  3. Update README.md

    haoxikang authored Aug 29, 2016
    Copy the full SHA
    b71c4d6 View commit details
  4. 修改bug

    haoxikang committed Aug 29, 2016
    Copy the full SHA
    aeae0e7 View commit details
  5. Copy the full SHA
    a559cd5 View commit details
  6. 修改bug

    haoxikang committed Aug 29, 2016
    Copy the full SHA
    6a47023 View commit details

Commits on Aug 30, 2016

  1. Copy the full SHA
    0bc6a97 View commit details
  2. Copy the full SHA
    55fabd1 View commit details
  3. Copy the full SHA
    22cdbcb View commit details

Commits on Sep 1, 2016

  1. Update README.md

    haoxikang authored Sep 1, 2016
    Copy the full SHA
    4f5975f View commit details

Commits on Sep 2, 2016

  1. Copy the full SHA
    210a18a View commit details
  2. Copy the full SHA
    85dad9c View commit details
  3. Update README.md

    haoxikang authored Sep 2, 2016
    Copy the full SHA
    1a15d11 View commit details

Commits on Sep 5, 2016

  1. Update README.md

    haoxikang authored Sep 5, 2016
    Copy the full SHA
    54fb44a View commit details

Commits on Sep 14, 2016

  1. 更新插件

    haoxikang committed Sep 14, 2016
    Copy the full SHA
    7011c0f View commit details
  2. Update README.md

    haoxikang authored Sep 14, 2016
    Copy the full SHA
    6905226 View commit details
  3. Copy the full SHA
    9ab55fd View commit details
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 15 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# WebViewList
![image](https://github.com/348476129/WebViewList/blob/master/gif5新文件.gif)
解决了 Webview+RecyclerView的滑动冲突。能让两个控件协同滑动。
如何导入:

@@ -13,14 +14,19 @@ Add it in your root build.gradle at the end of repositories:
Step 2. Add the dependency

dependencies {
compile 'com.github.348476129:WebViewList:0.1.2'
compile 'com.github.348476129:WebViewList:1.1.8'
}
使用方法:
第一步:在xml中:
用 WebScrollLayout 包裹 RecyclerView 代替 RecyclerView



第二步:在activity中:
使用方法:

第一步:

用 WebScrollLayout 包裹 RecyclerView 代替 RecyclerView

第二步:

在activity中:

private RecyclerView recyclerView;
private WebScrollLayout webScrollLayout;
@@ -29,7 +35,9 @@ Step 2. Add the dependency
webScrollLayout = (WebScrollLayout)findViewById(R.id.my_layout);
recyclerView = (RecyclerView)findViewById(R.id.recycler);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
WebViewAdapter webViewAdapter = new WebViewAdapter(new MyAdapter(),"http://wap.4c.cn");
ScrollWebView scrollWebView = new ScrollWebView(this);
scrollWebView.loadUrl(url);
WebViewAdapter webViewAdapter = new WebViewAdapter(new MyAdapter(),scrollWebView);
webScrollLayout.setRecyclerviewScrollBottomListener(new WebScrollLayout.RecyclerviewScrollBottom() {
@Override
public void onScrollBottom() {
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.example.administrator.webviewlist;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
@@ -16,35 +15,43 @@


public class MainActivity extends AppCompatActivity {
private RecyclerView recyclerView;
private RecyclerView recyclerView;
private Button button;
private WebScrollLayout webScrollLayout;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button)findViewById(R.id.button) ;
button = (Button) findViewById(R.id.button);

webScrollLayout = (WebScrollLayout)findViewById(R.id.my_layout);
recyclerView = (RecyclerView)findViewById(R.id.recycler);
webScrollLayout = (WebScrollLayout) findViewById(R.id.my_layout);
recyclerView = (RecyclerView) findViewById(R.id.recycler);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
WebViewAdapter webViewAdapter = new WebViewAdapter(new MyAdapter());
final ScrollWebView scrollWebView = new ScrollWebView(this);
scrollWebView.setWebViewClient(new WebViewClient(){
@Override
public void onPageFinished(WebView view, String url) {
WebViewAdapter webViewAdapter = new WebViewAdapter(new MyAdapter(), scrollWebView);
webViewAdapter.attachLayout(webScrollLayout);
recyclerView.setAdapter(webViewAdapter);
}
});
scrollWebView.loadUrl("http://wap.4c.cn");

webScrollLayout.setRecyclerviewScrollBottomListener(new WebScrollLayout.RecyclerviewScrollBottom() {
@Override
public void onScrollBottom() {
//滑动到了底部监听
}
});
webViewAdapter.attachLayout(webScrollLayout);
final ScrollWebView scrollWebView = new ScrollWebView(this);
scrollWebView.loadUrl("http://wap.4c.cn");
webViewAdapter.attachWebView(scrollWebView);
recyclerView.setAdapter(webViewAdapter);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
recyclerView.smoothScrollToPosition(20);
}
});

button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
webScrollLayout.scrollTop();

}
});
}
}
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -5,8 +5,8 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
classpath 'com.android.tools.build:gradle:2.2.0-beta2'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath 'com.android.tools.build:gradle:2.2.0-rc1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Binary file added gif5新文件.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
import android.view.MotionEvent;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;

/**
* Created by 康颢曦 on 2016/8/23.
@@ -20,17 +21,18 @@ public class ScrollWebView extends WebView {
private int maxH;

public ScrollWebView(Context context) {
super(context);
this(context,null);
}

public ScrollWebView(Context context, AttributeSet attrs) {
super(context, attrs);
this(context,attrs,0);
}

public ScrollWebView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}


@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public ScrollWebView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
@@ -42,6 +44,7 @@ public void ignoreTouchCancel(boolean val) {

@Override
public boolean onTouchEvent(MotionEvent ev) {

int action = ev.getAction();
if (action == MotionEvent.ACTION_DOWN) {
onScrollChanged(getScrollX(), getScrollY(), getScrollX(), getScrollY());
@@ -62,20 +65,50 @@ protected void onScrollChanged(int l, int t, int oldl, int oldt) {
}

@Override
protected void onSizeChanged(int w, int h, int ow, int oh) {
Log.d("onSizeChanged","h="+h);
if (h > maxH) {
ViewGroup.LayoutParams layoutParams = getLayoutParams();
layoutParams.height = maxH;
setLayoutParams(layoutParams);
isScroll = true;
}
if (h < maxH) {
isScroll = false;
public void postInvalidate() {
Log.d("TAG","内容高度,调用post");
super.postInvalidate();
}

@Override
public void invalidate() {

if (maxH!=0){
int h = (int) (getContentHeight()*getScale());
Log.d("TAG","内容高度"+h);
if (h>=maxH){
ViewGroup.LayoutParams layoutParams = getLayoutParams();
if (layoutParams.height!=maxH){
layoutParams.height = maxH;
setLayoutParams(layoutParams);

}
isScroll = true;
}else {
ViewGroup.LayoutParams layoutParams = getLayoutParams();
layoutParams.height = h;
setLayoutParams(layoutParams);
isScroll = false;
}
}
super.onSizeChanged(w, h, ow, oh);
super.invalidate();
}

// @Override
// protected void onSizeChanged(int w, int h, int ow, int oh) {
// Log.d("onSizeChanged","h="+h);
// if (h > maxH) {
// ViewGroup.LayoutParams layoutParams = getLayoutParams();
// layoutParams.height = maxH;
// setLayoutParams(layoutParams);
// isScroll = true;
// }
// if (h < maxH) {
// isScroll = false;
// }
// super.onSizeChanged(w, h, ow, oh);
// }

public void setOnCustomScroolChangeListener(ScrollInterface scrollInterface) {

this.mScrollInterface = scrollInterface;
Original file line number Diff line number Diff line change
@@ -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;

@@ -76,17 +77,20 @@ public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
mDispatchWebView.setOnCustomScroolChangeListener(new ScrollWebView.ScrollInterface() {
@Override
public void onSChanged(int l, int t, int oldl, int oldt) {
float webViewContentHeight = mDispatchWebView.getContentHeight() * mDispatchWebView.getScrollY();
Log.d("调用滑动事件",l+" "+t+" "+oldl+" "+oldt);
float webViewContentHeight = mDispatchWebView.getContentHeight() * mDispatchWebView.getScale();
Log.d("内容高度",webViewContentHeight+"");
float webViewCurrentHeight = (mDispatchWebView.getHeight() + mDispatchWebView.getScrollY());
Log.d("偏移量+页面高度",webViewCurrentHeight+"");
if ((webViewContentHeight - webViewCurrentHeight) <= 5) {
if ((webViewContentHeight - webViewCurrentHeight) <=5) {
System.out.println("WebView滑动到了底端");
if (isScrollUp && mDispatchWebView.isScroll()) {
mDispatchWebView.ignoreTouchCancel(false);
isIntercept = false;
}

}else {
System.out.println("WebView滑动到了不是底端");
}
}
});
@@ -125,7 +129,10 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
Log.d("Log", mDispatchWebView.getHeight() + "");
if (mDispatchWebView!=null){
Log.d("Log", mDispatchWebView.getHeight() + "");
}

switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
y1 = ev.getY();
@@ -134,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;

}
@@ -191,4 +199,30 @@ public interface RecyclerviewScrollBottom {
void onScrollBottom();

}
public void scrollTop(){
if (recyclerView!=null&&mDispatchWebView!=null){
Log.d("TAG","滑动到顶部,进入第一层");
recyclerView.scrollToPosition(0);
mDispatchWebView.scrollTo(0, 0);
if (mDispatchWebView.isScroll()){

Log.d("TAG","滑动到顶部,获取触摸事件");
mDispatchWebView.ignoreTouchCancel(true);
isIntercept = true;
}
}

}

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

recyclerView=null;
}
}
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -13,11 +14,11 @@

public class WebViewAdapter<T> extends RecyclerView.Adapter<RecyclerView.ViewHolder>
{

private int TPYE_WEB_VIEW=10;
private RecyclerView.Adapter mInnerAdapter;
private WebScrollLayout layout;
private ScrollWebView scrollWebView;
private ScrollWebView scrollWebView;

public RecyclerView.Adapter getmInnerAdapter() {
return mInnerAdapter;
}
@@ -26,30 +27,30 @@ public void setmInnerAdapter(RecyclerView.Adapter mInnerAdapter) {
this.mInnerAdapter = mInnerAdapter;
}

public WebViewAdapter(RecyclerView.Adapter adapter)
public WebViewAdapter(RecyclerView.Adapter adapter , ScrollWebView scrollWebView)
{
this.scrollWebView = scrollWebView;
mInnerAdapter = adapter;

}

public void attachLayout(WebScrollLayout layout){
this.layout=layout;
}
public void attachWebView(ScrollWebView webView){
scrollWebView = webView;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
{
if (viewType==TPYE_WEB_VIEW)
{
WebViewHolder holder = new WebViewHolder(scrollWebView);

holder.webView.setMaxH(parent.getHeight());
layout.preventParentTouchEvent(holder.webView);
return holder;
if (viewType==TPYE_WEB_VIEW)
{
WebViewHolder holder = new WebViewHolder(scrollWebView);
holder.webView.setMaxH(parent.getHeight());
Log.d("Log"," "+holder.webView.getContentHeight());
ViewGroup.LayoutParams layoutParams =new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
holder.webView. setLayoutParams(layoutParams);
layout.preventParentTouchEvent(holder.webView);
return holder;

}
}
return mInnerAdapter.onCreateViewHolder(parent, viewType);
}

@@ -119,7 +120,7 @@ class WebViewHolder extends RecyclerView.ViewHolder {
ScrollWebView webView ;
public WebViewHolder(View itemView) {
super(itemView);
webView =(ScrollWebView) itemView;
webView =(ScrollWebView)itemView;
}
}

Loading