android – 使用Horizo​​ntalScrollView将DrawerLayout导入内容菜单

我的问题很简单.我可以在DrawerLayout的内容菜单中使用Horizo​​ntalScrollView吗?
我的DrawerLayout看起来像这样:

在片段内部我有Horizo​​ntalScrollView但是当我尝试触摸它时没有任何事情发生,因为抽屉布局跟随我的手指.
我认为禁用内容菜单中的触摸事件并仅在单击主内容视图时使DrawerLayout可关闭将解决我的问题.真的吗?如果没有,有人可以告诉我,我该怎么办?

谢谢.

最佳答案
基于此解决方案:https://stackoverflow.com/a/7258579/452486

我已经能够使Horizo​​ntalScrollView可滚动.
创建一个类扩展DrawerLayout:

public class AllowChildInterceptTouchEventDrawerLayout extends DrawerLayout {

    private int mInterceptTouchEventChildId;

    public void setInterceptTouchEventChildId(int id) {
       this.mInterceptTouchEventChildId = id;
    }

    public AllowChildInterceptTouchEventDrawerLayout(Context context) {
    super(context);
    }

    public AllowChildInterceptTouchEventDrawerLayout(Context context,AttributeSet attrs) {
        super(context,attrs);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {

        if (mInterceptTouchEventChildId > 0) {
            View scroll = findViewById(mInterceptTouchEventChildId);
            if (scroll != null) {
                Rect rect = new Rect();
                scroll.getHitRect(rect);
                if (rect.contains((int) ev.getX(),(int) ev.getY())) {
                    return false;
                }
            }
        }
        return super.onInterceptTouchEvent(ev);

        }
    }

添加拦截drawerlayout的触摸事件的子ID

AllowChildInterceptTouchEventDrawerLayout drawerLayout = (AllowChildInterceptTouchEventDrawerLayout) findViewById(R.id.layoutdrawer_id);
drawerLayout.setInterceptTouchEventChildId(R.id.horizontalscrollview_id);

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...