SnapScroll
Package com.realeyez.trademart.gui.components.scroll
For scrolling through panels of equal sizes wherein when you scroll vertically, you want to snap to the next panel, the SnapScroll panel class should be used. This behavior is comparable to scrolling through tiktok or youtube shorts. All you need to do is create an instance of this and provide it a ScrollView to apply the scroll snapping to.
TIP
The SnapScrollH
is a horizontal version of this class.
Constructors
SnapScroll(ScrollView)
public SnapScroll(ScrollView scrollView)
SnapScroll must be instanciated with this constructor.
Fields
scrollView
private ScrollView scrollView;
The target ScrollView to apply the snap scrolling on.
lastY
private int lastY;
The last y position before scrolling starts.
curChild
private int curChild;
The index of the currently focused child of the children of the scrollView
's child.
Methods
snap()
private void snap()
The snapping logic of the scroll panel. This is called everytime the MotionEvent.ACTION_UP action is invoked in the OnTouchListener of the scrollView
.
applyScrollEvent()
private void applyScrollEvent()
Applies the onTouchEvent for the scrollView
.
getCurChild()
public int getCurChild()
Get the value of curChild
.