Skip to content

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)

java
public SnapScroll(ScrollView scrollView)

SnapScroll must be instanciated with this constructor.

Fields

scrollView

java
private ScrollView scrollView;

The target ScrollView to apply the snap scrolling on.

lastY

java
private int lastY;

The last y position before scrolling starts.

curChild

java
private int curChild;

The index of the currently focused child of the children of the scrollView's child.

Methods

snap()

java
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()

java
private void applyScrollEvent()

Applies the onTouchEvent for the scrollView.

getCurChild()

java
public int getCurChild()

Get the value of curChild.