[英]How to stop scroll ScrollView when show speicific view in ScrollView?
How to stop scroll ScrollView when show speicific view in ScrollView ? 在ScrollView中显示特定视图时如何停止Scroll ScrollView?
.....
View2
----------------------------------
| |
| View3 |
| |
| |
| View4 |
| |
| | <------ It's Screen
| View5 |
| |
| |
| View6 |
| |
| |
| View7 |
| |
| |
| View8 |
| |
| |
| View9 |
----------------------------------
View10
......
How to catch moment when View9 is showed and stop scrolling. 如何在显示View9时捕捉瞬间并停止滚动。
I never had to do this but here is what I would do. 我从来不需要这样做,但是这就是我要做的。
First, you need to detect when your View9 is diplayed and visible. 首先,您需要检测View9何时显示和可见。 So I would use something like this 所以我会用这样的东西
Rect scrollBounds = new Rect();
scrollView.getHitRect(scrollBounds);
if (imageView.getLocalVisibleRect(scrollBounds)) {
// imageView is within the visible window
} else {
// imageView is not within the visible window
}
(from https://stackoverflow.com/a/12428208/3187128 ) (来自https://stackoverflow.com/a/12428208/3187128 )
Try to execute this every X second to test the code. 尝试每隔X秒执行一次以测试代码。
Then, if you want something cleaner, you should use a scrollListener: 然后,如果您想要更清洁的东西,则应使用scrollListener:
scrollView.getViewTreeObserver().addOnScrollChangedListener(new OnScrollChangedListener() {
@Override
public void onScrollChanged() {
int scrollX = rootScrollView.getScrollX(); //for horizontalScrollView
int scrollY = rootScrollView.getScrollY(); //for verticalScrollView
//DO SOMETHING WITH THE SCROLL COORDINATES
}
});
(from https://stackoverflow.com/a/23365539/3187128 ) (来自https://stackoverflow.com/a/23365539/3187128 )
Last step would be to implement a custom scrollview to be able to disable the scrolling : 最后一步是实现一个自定义的scrollview以便能够禁用滚动:
cf https://stackoverflow.com/a/5763815/3187128 cf https://stackoverflow.com/a/5763815/3187128
Hope this will help :) 希望这会有所帮助:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.