android – 抽屉里面的SwipeRefreshLayout里面的ListView(布局):不锁定滚动方向

android – 抽屉里面的SwipeRefreshLayout里面的ListView(布局):不锁定滚动方向,第1张

概述ListView在滚动开始的方向上锁定其滚动方向.这适用于此配置: DrawerLayout ListView 当我向上/向下滑动时,列表会滚动.当我向左滚动时,抽屉关闭:完美.当我开始向下滑动然后改变方向时,初始方向(水平/垂直)被锁定. 但是,如果我将列表包装在SwipeRefreshLayout中,如下所示: DrawerLayout SwipeRefreshLayout ListVIEw在滚动开始的方向上锁定其滚动方向.这适用于此配置:

DrawerLayout    ListVIEw

当我向上/向下滑动时,列表会滚动.当我向左滚动时,抽屉关闭:完美.当我开始向下滑动然后改变方向时,初始方向(水平/垂直)被锁定.

但是,如果我将列表包装在SwipeRefreshLayout中,如下所示:

DrawerLayout    SwipeRefreshLayout        ListVIEw

..然后锁定滚动/滑动方向不再起作用.当我向上/向下滑动然后向左/向右滑动一下时,列表会滚动并且抽屉也会移动.后者不是我想要的.

有关如何使用SwipeRefreshLayout恢复前一行为的任何建议?

解决方法 我有同样的问题,但使用RecyclerVIEw而不是ListVIEw.最简单的解决方法是扩展SwipeRefreshLayout,当检测到向下滚动时,告诉父(抽屉)布局不要拦截事件(例如滑动抽屉).

import androID.content.Context;import androID.support.v4.Widget.SwipeRefreshLayout;import androID.util.AttributeSet;import androID.vIEw.MotionEvent;import androID.vIEw.VIEwConfiguration;public class DrawerSwipeRefreshLayout extends SwipeRefreshLayout {    private int touchSlop;    private float initialDownY;    public DrawerSwipeRefreshLayout(Context context,AttributeSet attrs) {        super(context,attrs);        touchSlop = VIEwConfiguration.get(context).getScaledtouchSlop();    }    @OverrIDe    public boolean onIntercepttouchEvent(MotionEvent event) {        switch (event.getAction()) {            case MotionEvent.ACTION_DOWN:                initialDownY = event.getY();                break;            case MotionEvent.ACTION_MOVE:                final float eventY = event.getY();                float yDiff = Math.abs(eventY - initialDownY);                if (yDiff > touchSlop) {                    getParent().requestdisallowIntercepttouchEvent(true);                }        }        return super.onIntercepttouchEvent(event);    }}
总结

以上是内存溢出为你收集整理的android – 抽屉里面的SwipeRefreshLayout里面的ListView(布局):不锁定滚动方向全部内容,希望文章能够帮你解决android – 抽屉里面的SwipeRefreshLayout里面的ListView(布局):不锁定滚动方向所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1125557.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存