简体   繁体   English

具有捕捉效果的水平Scrollview

[英]Horizontal Scrollview with snap effect

I need a widget that functions as a horizontal scrollview, but snaps to the nearest value when scrolled (it should snap from value to value, and not be possible to stop the scrolling in between values). 我需要一个可用作水平滚动视图的小部件,但在滚动时会捕捉到最接近的值(它应该在一个值之间捕捉,并且不可能停止在两个值之间的滚动)。 Theoretically I would solve this with a viewpager with negative margins - so that all the views are simultaneously visible, but it also "snaps". 从理论上讲,我将使用带有负边距的viewpager来解决此问题-这样所有视图都可以同时可见,但是它也可以“捕捉”。 But I have a problem - if I use a viewpager then only the "foreground" (ie currentView) view is "clickable", and I need all onscreen visible views to be clickable at any given time. 但是我有一个问题-如果我使用viewpager,那么只有“前景”(即currentView)视图是“可点击的”,并且我需要所有屏幕上可见的视图在任何给定时间都是可点击的。 So - is there any way of having a "snapping" horizontal scroll widget where all visible views are clickable? 所以-有没有办法让所有可见的视图都可单击的“捕捉”水平滚动小部件?

For example, the screen might look like this: 例如,屏幕可能如下所示:

ABCDE ABCDE

where scrolling right reveals F, G, H.. 向右滚动显示F,G,H。

initial state should allow clicking on any of A,B,C,D,E and not just on A (if it was the "currentview") 初始状态应允许单击A,B,C,D,E中的任何一个,而不仅仅是单击A(如果它是“ currentview”)

You can use Snap ScrollView library. 您可以使用Snap ScrollView库。 It supports both horizontal and vertical snap scrolling. 它支持水平和垂直快照滚动。 You can add views directly. 您可以直接添加视图。 Click on this SnapScrollView library 单击此SnapScrollView

And regarding click, you can implement onClick listener for each view and call correspondingly. 对于点击,您可以为每个视图实现onClick侦听器并相应地调用。

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

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