首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >android问题中滚动视图中的滚动视图

android问题中滚动视图中的滚动视图
EN

Stack Overflow用户
提问于 2013-07-16 16:01:25
回答 3查看 9.3K关注 0票数 7

我在滚动视图中有一个滚动视图。xml是这样的

代码语言:javascript
复制
<RelativeLayout ....
    <ScrollView.....
         <RelativeLayout ....
           <Button.....
           <Button ....
           <ScrollView
             <RelativeLayout ....
                 ..........
               </RelativeLayout>
             </ScrollView>
         </RelativeLayout>
     </ScrollView>
 </RelativeLayout>

在此第二个滚动视图中滚动不流畅。可以给出一个解决方案。我尝试了互联网上给出的许多解决方案,但都不起作用。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-07-16 16:40:47

试试这段代码。它正在为我工作。

代码语言:javascript
复制
 parentScrollView.setOnTouchListener(new View.OnTouchListener() {

public boolean onTouch(View v, MotionEvent event)
{
    findViewById(R.id.childScrollView).getParent().requestDisallowInterceptTouchEvent(false);
return false;
}
});
childScrollView.setOnTouchListener(new View.OnTouchListener() {

public boolean onTouch(View v, MotionEvent event)
{

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

Stack Overflow用户

发布于 2014-05-28 06:15:43

另一种解决方案是将此类用作父类。

代码语言:javascript
复制
public class NoInterceptScrollView extends ScrollView {

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

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return false;
    }

}
票数 7
EN

Stack Overflow用户

发布于 2014-12-16 10:37:58

我不得不改进Deepthi的解决方案,因为它对我不起作用;我猜是因为我的孩子的滚动视图充满了视图(我的意思是说,孩子的视图使用了所有的滚动视图绘图空间)。为了使其具有完整的功能,我还必须在触摸子滚动视图内的所有子视图时禁止对父滚动的触摸请求:

代码语言:javascript
复制
parentScrollView.setOnTouchListener(new View.OnTouchListener() {
    public boolean onTouch(View v, MotionEvent event)
    {
        findViewById(R.id.childScrollView).getParent().requestDisallowInterceptTouchEvent(false);
        return false;
    }
});
childScrollView.setOnTouchListener(new View.OnTouchListener() {
    public boolean onTouch(View v, MotionEvent event)
    {
        // Disallow the touch request for parent scroll on touch of
        // child view
        v.getParent().requestDisallowInterceptTouchEvent(true);
        return false;
    }
});`
childScrollviewRecursiveLoopChildren(parentScrollView, childScrollView);
public void childScrollviewRecursiveLoopChildren(final ScrollView parentScrollView, View parent) {
    for (int i = ((ViewGroup) parent).getChildCount() - 1; i >= 0; i--) {
        final View child = ((ViewGroup) parent).getChildAt(i);
        if (child instanceof ViewGroup) {
            childScrollviewRecursiveLoopChildren(parentScrollView, (ViewGroup) child);
        } else {
            child.setOnTouchListener(new View.OnTouchListener() {
                public boolean onTouch(View v, MotionEvent event)
                {
                    // Disallow the touch request for parent scroll on touch of
                    // child view
                    parentScrollView.requestDisallowInterceptTouchEvent(true);
                    return false;
                }
            });
        }
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17671123

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档