Skip to content

Commit

Permalink
正式版本
Browse files Browse the repository at this point in the history
  • Loading branch information
haoxikang committed Aug 26, 2016
1 parent e46afd8 commit 0a1d341
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 17 deletions.
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.

Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 0a1d341

Please sign in to comment.