解决SwipeRefreshLayout和webview下拉刷新冲突问题
2017-12-24 22:30
429 查看
在SwipeRefreshLayout中嵌套webview时,默认无论在网页任何位置下拉都会触发刷新,实际需求是只在顶部需要,解决方法是继承SwipeRefreshLayout,复写其中的canScrollUp方法:
然后在使用时传入webview即可:
import android.content.Context; import android.support.v4.widget.SwipeRefreshLayout; import android.util.AttributeSet; import android.view.ViewGroup; public class ScrollSwipeRefreshLayout extends SwipeRefreshLayout { // 子布局 这里为webview private ViewGroup mChildViewGroup; public ScrollSwipeRefreshLayout(Context context) { super(context); } public ScrollSwipeRefreshLayout(Context context, AttributeSet attrs) { super(context, attrs); } public ViewGroup getViewGroup() { return mChildViewGroup; } public void setViewGroup(ViewGroup viewGroup) { mChildViewGroup = viewGroup; } /** * @return Whether it is possible for the child view of this layout to * scroll up. Override this if the child view is a custom view. */ @Override public boolean canChildScrollUp() { if (null != mChildViewGroup) { if (mChildViewGroup.getScrollY() > 0) { return true; } return false; } return super.canChildScrollUp(); } }
然后在使用时传入webview即可:
mRefreshLayout.setViewGroup(webView);
相关文章推荐
- 关于webview加载网页,返回后总是刷新页面问题解决
- 下拉刷新时UITableView的section headerView冲突的解决
- fragment加载webView与ViewPager所带来的滑动冲突问题解决方法
- android——webview解决goback()后,界面会刷新的问题
- 使用列表组织WebView解决返回页面总是刷新的问题
- ScrollView和Fragment中的ListView、WebView滑动冲突问题的解决
- 解决AngularJS在安卓WebView中跳转时不刷新的问题
- webview和swiperefreshLayout 的下拉冲突问题
- web应用json转换引起jar包冲突的问题及解决方法
- WKWebView使用遇到的问题与解决办法
- 下拉刷新 上拉更多 支持ListView GridView WebView
- 追溯源码解决android疑难问题1--Viewpager之notifyDataSetChanged无刷新
- 自定义viewpager实现滑动拦截与分发解决嵌套listview等滑动冲突问题
- 渐变toolbar,悬浮控件,scrollview和recycleview滑动冲突及显示不全问题解决
- 解决ScrollView嵌套viewpager冲突问题
- Android WebView 软键盘遮挡输入框问题的解决方法
- android与ios的webView中html中的js冲突问题
- android webview 字体切换 反白乱的问题解决
- Android中的WebView进行直接加载网页(要注意解决权限问题)
- 带你解决 WebView 里的常见问题