在Android嵌套滚动 [英] Nested scrolling on Android

查看:136
本文介绍了在Android嵌套滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经在我们的活动主要横向滚动视图,并嵌套在它的几个垂直滚动的看法。我们的想法是水平滚动,直到你找到你想要的垂直列表,然后滚动的向上和向下。

We have a main horizontal scroll view in our activity, and several vertical scroll views nested inside it. The idea is to scroll horizontally till you find the vertical list you want, then scroll that up and down.

在理想情况下,我愿意垂直滚动有一个锁定一旦你开始垂直滚动。现在会发生什么,如果你很小心,你可以垂直滚动,但如果你的手指有点太多移动到左/右在做的过程中,垂直站和水平接管。

Ideally, I'd want the vertical scrolling to have a "lock" once you start scrolling vertically. What happens now, if you're very careful, you can scroll vertically, but if you move your finger a little too much to the left/right while doing it, the vertical stops and the horizontal takes over.

这很可能会令意义上,无论滚动视图被激活首先你的运动,直到你完成你的相互作用(即松开手指)。

What would probably make sense is, whatever scroll view gets "activated" first by your movement, that one stays active until you finish your interaction (ie remove your finger).

任何方法,使之作用一样?

Any way to make it behave like that?

推荐答案

这可能是更好的使用ViewPager为卧式刷卡,如果它会为您的应用程序。

It may be better to use a ViewPager for the horizontal swiping, if it would work for your app.

如果这行不通,尝试覆盖的垂直ScrollViews的onTouch方法,使他们prevent水平滚动视图使用滚动

If that wouldn't work, try overriding the onTouch method of the vertical ScrollViews so that they prevent the horizontal scroll view from scrolling using

  scrollView.setEnabled(false)

有ScrollViews嵌套在其它ScrollViews里面通常是一个不好的做法,因为它通常是很难为用户导航,所以你可能需要考虑重新设计活动,以避免这个问题。

Having ScrollViews nested inside of other ScrollViews is generally a bad practice since it is usually harder for the user to navigate, so you may need to consider redesigning that Activity to avoid this problem.

如果你必须使用嵌套ScrollViews,我发现这个二维滚动型类可以帮助你。

If you must use nested ScrollViews, I found this two-dimensional ScrollView class that may help you.

这篇关于在Android嵌套滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆