具有捕捉效果的水平Scrollview [英] Horizontal Scrollview with snap effect

查看:58
本文介绍了具有捕捉效果的水平Scrollview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个可用作水平滚动视图的小部件,但在滚动时会捕捉到最接近的值(它应该在一个值之间捕捉,并且不可能停止在两个值之间的滚动).从理论上讲,我将使用带有负边距的viewpager来解决此问题-这样所有视图都可以同时可见,但是它也可以捕捉".但是我有一个问题-如果我使用viewpager,那么只有前景"(即currentView)视图是可点击的",并且我需要所有屏幕上可见的视图在任何给定时间都是可点击的.那么-有没有办法让所有可见的视图都可单击的捕捉"水平滚动小部件?

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". But I have a problem - if I use a viewpager then only the "foreground" (i.e. currentView) view is "clickable", and I need all onscreen visible views to be clickable at any given time. 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:

A B C D E

A B C D E

向右滚动显示F,G,H.

where scrolling right reveals F, G, H..

初始状态应允许单击A,B,C,D,E中的任何一个,而不是仅单击A(如果它是当前视图")

initial state should allow clicking on any of A,B,C,D,E and not just on A (if it was the "currentview")

推荐答案

您可以使用Snap ScrollView库.它支持水平和垂直快照滚动.您可以直接添加视图.单击此 SnapScrollView

You can use Snap ScrollView library. It supports both horizontal and vertical snap scrolling. You can add views directly. Click on this SnapScrollView library

关于点击,您可以为每个视图实现onClick侦听器并相应地调用.

And regarding click, you can implement onClick listener for each view and call correspondingly.

这篇关于具有捕捉效果的水平Scrollview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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