简体   繁体   English

如何在android中滚动子滚动视图时停止滚动父滚动视图?

[英]How to stop the scrolling of parent scroll view when child scroll view is scrolled in android?

I know we can use touchlisteners for both scroll view,like 我知道我们可以在两个滚动视图中使用touchlisteners

parentScrollView.setOnTouchListener(new View.OnTouchListener() {

    @Override
    public boolean onTouch(View v, MotionEvent event) {
    Log.v(TAG, "PARENT TOUCH");

    findViewById(R.id.child_scroll).getParent()
            .requestDisallowInterceptTouchEvent(false);
    return false;
    }
});

childScrollView.setOnTouchListener(new View.OnTouchListener() {

    @Override
    public boolean onTouch(View v, MotionEvent event) {
    Log.v(TAG, "CHILD TOUCH");

    // Disallow the touch request for parent scroll on touch of  child view
    v.getParent().requestDisallowInterceptTouchEvent(true);
    return false;
    }
});

what I am facing is my child scroll view is not the immediate child to the parent scroll view.In this v.getParent() is not working and when I touch and try to scroll my child scroll view the whole main scroll is scrolling. 我面临的是我的子滚动视图不是父滚动视图的直接子视图。在此v.getParent()不起作用,当我触摸并尝试滚动我的子滚动视图时,整个主滚动滚动。

Positions of my scroll views in my layout(views are dynamically created so I need to go with so much layouts) 我的滚动视图在我的布局中的位置(视图是动态创建的,因此我需要使用这么多布局)

linearLayout
  ParentscrollView(0)
          linearLayout(0)
              relativeLayout(0)
                       TextView(0)
              relativeLayout(1)
                    childScrollView(0)

need help..Thanks in advance.!! 需要帮助。谢谢。!!

Isn't findViewById() for parent scroll view id not working? 是不是findViewById()父滚动视图ID不起作用?

childScrollView.setOnTouchListener(new View.OnTouchListener() {

    @Override
    public boolean onTouch(View v, MotionEvent event) {
    Log.v(TAG, "CHILD TOUCH");

    // Disallow the touch request for parent scroll on touch of  child view
    findViewById(parentLayouttId).requestDisallowInterceptTouchEvent(true);
    return false;
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM