解决SwipeRefreshLayout和webview下拉刷新冲突问题

来源:互联网 发布:c语言char转int 编辑:程序博客网 时间:2024/03/28 22:47

在SwipeRefreshLayout中嵌套webview时,默认无论在网页任何位置下拉都会触发刷新,实际需求是只在顶部需要,解决方法是继承SwipeRefreshLayout,复写其中的canScrollUp方法:

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);
阅读全文
'); })();
0 0
原创粉丝点击
热门IT博客
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 姓张男明星 我姓张作品 张姓族谱二十四辈分 张姓男孩100分名字 张姓家谱辈份顺序 张姓名字大全 张姓女孩取名大全 张姓女孩 张姓宝宝取名字大全 姓张男孩名 姓张的 玉皇大帝为什么姓张 强宗右姓 强姓 强姓女孩取名 强姓取名 姓强的名字 惠姓 惠姓怎么读 惠姓男孩起名 惠这个姓为什么有人读xi 姓惠 鲜卑族汉姓 姓景的女孩名字 景姓男孩名字 姓景 景姓女孩名字 曹姓 曹姓起源 姓曹女孩名字 姓曹名字 给姓曹的女孩起名 曹姓辈分 我姓曹图片文字唯美 2018男孩曹姓霸气有涵养的名字 姓曹的男孩洋气名字 曹姓宝宝取名字 曹姓男孩取名 曹姓宝宝起名大全 2018年曹姓男孩起100分名字 曹姓男孩名字