From 0a1d341330b22db8b0659f4164cc298f7efb43cd Mon Sep 17 00:00:00 2001
From: fallllllll <348476129@qq.com>
Date: Fri, 26 Aug 2016 14:07:17 +0800
Subject: [PATCH] =?UTF-8?q?=E6=AD=A3=E5=BC=8F=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.idea/misc.xml | 2 +-
.../webviewlist/MainActivity.java | 4 +-
.../example/webviewscroll/ScrollWebView.java | 55 ++++++++++++++-----
.../webviewscroll/WebScrollLayout.java | 5 +-
.../example/webviewscroll/WebViewAdapter.java | 4 ++
5 files changed, 53 insertions(+), 17 deletions(-)
diff --git a/.idea/misc.xml b/.idea/misc.xml
index cca2cda..7158618 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -37,7 +37,7 @@
-
+
diff --git a/app/src/main/java/com/example/administrator/webviewlist/MainActivity.java b/app/src/main/java/com/example/administrator/webviewlist/MainActivity.java
index 4068325..3c5f516 100644
--- a/app/src/main/java/com/example/administrator/webviewlist/MainActivity.java
+++ b/app/src/main/java/com/example/administrator/webviewlist/MainActivity.java
@@ -27,8 +27,8 @@ protected void onCreate(Bundle savedInstanceState) {
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");
+ recyclerView.setLayoutManager(new LinearLayoutManager(this));
+ WebViewAdapter webViewAdapter = new WebViewAdapter(new MyAdapter(),"https://app.4c.cn/web/details?nid=234&systemType=android&phoneName=E6683&phoneCode=33e129936a25fb1ac94f351e2fea6076");
webScrollLayout.setRecyclerviewScrollBottomListener(new WebScrollLayout.RecyclerviewScrollBottom() {
@Override
public void onScrollBottom() {
diff --git a/webviewscroll/src/main/java/com/example/webviewscroll/ScrollWebView.java b/webviewscroll/src/main/java/com/example/webviewscroll/ScrollWebView.java
index 87981ae..b447dee 100644
--- a/webviewscroll/src/main/java/com/example/webviewscroll/ScrollWebView.java
+++ b/webviewscroll/src/main/java/com/example/webviewscroll/ScrollWebView.java
@@ -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);
@@ -62,20 +64,47 @@ 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();
+ 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;
diff --git a/webviewscroll/src/main/java/com/example/webviewscroll/WebScrollLayout.java b/webviewscroll/src/main/java/com/example/webviewscroll/WebScrollLayout.java
index 9d67187..753b74f 100644
--- a/webviewscroll/src/main/java/com/example/webviewscroll/WebScrollLayout.java
+++ b/webviewscroll/src/main/java/com/example/webviewscroll/WebScrollLayout.java
@@ -125,7 +125,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();
diff --git a/webviewscroll/src/main/java/com/example/webviewscroll/WebViewAdapter.java b/webviewscroll/src/main/java/com/example/webviewscroll/WebViewAdapter.java
index 8828446..9504a1b 100644
--- a/webviewscroll/src/main/java/com/example/webviewscroll/WebViewAdapter.java
+++ b/webviewscroll/src/main/java/com/example/webviewscroll/WebViewAdapter.java
@@ -45,6 +45,10 @@ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType
parent.getContext()).inflate(R.layout.view_web, parent,
false));
holder.webView.setMaxH(parent.getHeight());
+ Log.d("Log"," "+holder.webView.getContentHeight());
+// ViewGroup.LayoutParams layoutParams =holder.webView. getLayoutParams();
+// layoutParams.height = parent.getHeight();
+// holder.webView. setLayoutParams(layoutParams);
layout.preventParentTouchEvent(holder.webView);
return holder;