重叠的滚动视图

发布于 2024-12-24 21:15:23 字数 214 浏览 4 评论 0原文

我有一个问题...我在绝对布局中有两个滚动视图。换句话说,它们是全屏的,并且彼此重叠,

顶部滚动视图是水平滚动视图,底部滚动视图是垂直滚动视图。

当我水平滚动时,我希望顶部滚动,当我垂直滚动时,我希望底部滚动。

但我的问题是水平滚动视图接受所有滚动事件,因此底部的滚动视图永远不会收到滚动事件...

我该如何解决这个问题?

提前致谢!

I have a problem... I have two scrollviews in a absolutelayout. in other words they are fullscreen and laying over each other

the top scrollview is a horizontal scrolling one and the bottom one is a vertical scrolling scrollview.

when I scroll horizontal I want the top one to scroll and when I scroll vertical I want the bottom one to scroll.

but my problem is that the horizontal scrollview takes all scroll events so the bottom one never receives a scroll event...

How can I resolve this?

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

薄凉少年不暖心 2024-12-31 21:15:23

把它们嵌套起来怎么样?您可以通过填充和边距使其在视觉上看起来相同,此外您还可以控制哪个视图处理触摸。

我不确定你是否可以说一个滚动视图应该只处理水平方向,而另一个滚动视图应该只处理垂直方向 - 可能不是。但是您可以重写 onTouchEvent 和 onInterceptTouchEvent 来定义您需要的任何行为! (查看 http://developer.android.com/reference/android/view/ GestureDetector.html

例如,如果您希望父滚动视图仅处理垂直滚动,而子滚动视图处理水平滚动,则应该

-override onInterceptTouchEvent(Event e) {
      if (e.getAction() == ACTION_DOWN){
        //dispatch the call manually to the scroll view below you 
        mChild.onTouchEvent(e);
        super.onTouchEvent(e);
      }
      if (e.getAction() == ACTION_MOVE && the move is horizontal){
         mChild.onTouchEvent(e);
      } else {
         super.onTouchEvent(e); 
     }
      return true;
}

}

或类似的内容。这不是你应该做什么,但你明白了。

How about nesting them? You can make it look visually the same, via paddings and margins and furthermore you can control which view handles the touches.

I am not sure if you can say that one scroll view should handle only horizontal and the other to handle only vertical - probably not. But you can override onTouchEvent and onInterceptTouchEvent in both to define whatever behaviour you need! (Check out http://developer.android.com/reference/android/view/GestureDetector.html )

For example, if you want the parent scroll view to handle only vertical scroll, and the child the handle horizontal, you should

-override onInterceptTouchEvent(Event e) {
      if (e.getAction() == ACTION_DOWN){
        //dispatch the call manually to the scroll view below you 
        mChild.onTouchEvent(e);
        super.onTouchEvent(e);
      }
      if (e.getAction() == ACTION_MOVE && the move is horizontal){
         mChild.onTouchEvent(e);
      } else {
         super.onTouchEvent(e); 
     }
      return true;
}

}

Or something like that. It is not exaclty what you should do, but you get the idea.

離殇 2024-12-31 21:15:23

您可能需要为此实现自定义控件。您的自定义控件需要一个 Scroller 类。您也可以下载 ScrollView类的源码并修改为双向。

并且不要将可滚动的东西放入其他可滚动的东西中 - 它们往往会争夺触摸事件。

You'll probably need to implement a custom control for this. You'll need a Scroller class for your custom control. Also you can download source code for ScrollView class and modify it to be bidirectional.

And don't put scrollable things into other scrollable things - they tend to fight over touch events.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文