public class ScrollHelper extends Object
The animation values include the scrolling distance, whether the scrolling ends, speed of throwing the animation, and speed of accelerating and decelerating the animation.
| 限定符和类型 | 字段 | 说明 |
|---|---|---|
static int |
AXIS_X |
Indicates that the x coordinate axis.
|
static int |
AXIS_Y |
Indicates that the y coordinate axis.
|
| 构造器 | 说明 |
|---|---|
ScrollHelper() |
Default constructor used to create a
ScrollHelper instance. |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
void |
abortAnimation() |
Stops an animation by stopping the calculation of the animation position.
|
void |
doFling(int startX,
int startY,
int velocityX,
int velocityY,
int minX,
int maxX,
int minY,
int maxY) |
Starts flinging the content.
|
void |
doFlingX(int startX,
int velocityX,
int minX,
int maxX) |
Starts flinging along the x axis.
|
void |
doFlingY(int startY,
int velocityY,
int minY,
int maxY) |
Starts flinging along the y axis.
|
int |
getCurrValue(int direction) |
Obtains the X/Y-axis coordinate during scrolling or flinging.
|
float |
getCurrVelocity() |
Obtains the current velocity.
|
int |
getFlingDistanceX(int velocityX) |
Obtains the flinging distance on the x axis.
|
int |
getFlingDistanceY(int velocityY) |
Obtains the flinging distance on the y axis.
|
int |
getFlingVelocityX() |
Obtains the flinging velocity on the x axis.
|
int |
getFlingVelocityY() |
Obtains the flinging velocity on the y axis.
|
float |
getFriction() |
Obtains the amount of friction.
|
int |
getHorizontalBeginPosition() |
Obtains the x coordinate where scrolling starts.
|
int |
getScrollDistanceX() |
Obtains the scrolling distance on the x axis.
|
int |
getScrollDistanceY() |
Obtains the scrolling distance on the y axis.
|
boolean |
isFinished() |
Determines whether scrolling or flinging is finished.
|
boolean |
isOverScrolled() |
Checks whether the content has scrolled to a valid position.
|
void |
setFriction(float friction) |
Sets the amount of simulated friction to calculate the current speed.
|
void |
startScroll(int startX,
int startY,
int dx,
int dy) |
Starts scrolling the content a component.
|
void |
startScrollX(int startX,
int dx) |
Starts scrolling along the x axis.
|
void |
startScrollY(int startY,
int dy) |
Starts scrolling along the y axis.
|
boolean |
updateScroll() |
Updates the position of a flinging or scrolling animation.
|
public static final int AXIS_X
public static final int AXIS_Y
public ScrollHelper()
ScrollHelper instance.public void doFling(int startX,
int startY,
int velocityX,
int velocityY,
int minX,
int maxX,
int minY,
int maxY)
This method is also used to set the fling speed and distance.
startX - Indicates the X-axis coordinate of the start point to fling.startY - Indicates the Y-axis coordinate of the start point to fling.velocityX - Indicates the initial velocity on X-axis, in unit of pixels per second. The value can be
negative, indicating that the component is slowing down.velocityY - Indicates the initial velocity on the Y-axis, in unit of pixels per second. The value can be
negative, indicating that the component is slowing down.minX - Indicates the minimum fling distance on X-axis.maxX - Indicates the maximum fling distance on X-axis.minY - Indicates the minimum fling distance on Y-axis.maxY - Indicates the maximum fling distance on Y-axis.public void doFlingX(int startX,
int velocityX,
int minX,
int maxX)
You can also use this method to set the fling velocity and distance.
startX - Indicates the x coordinate where flinging starts.velocityX - Indicates the number of pixels moved on the x axis per second.minX - Indicates the minimum flinging distance on the x axis.maxX - Indicates the maximum flinging distance on the x axis.public void doFlingY(int startY,
int velocityY,
int minY,
int maxY)
You can also use this method to set the fling velocity and distance.
startY - Indicates the y coordinate where flinging starts.velocityY - Indicates the number of pixels moved on the y axis per second.minY - Indicates the minimum flinging distance on the y axis.maxY - Indicates the maximum flinging distance on the y axis.public void startScrollX(int startX,
int dx)
startX - Indicates the x coordinate where scrolling starts.dx - Indicates the scrolling distance on the x axis. A positive value indicates scrolling leftwards,
and a negative value indicates scrolling rightwards.public void startScrollY(int startY,
int dy)
startY - Indicates the y coordinate where scrolling starts.dy - Indicates the scrolling distance on the y axis. A positive value indicates scrolling upwards,
and a negative value indicates scrolling downwards.public int getFlingDistanceX(int velocityX)
velocityX - Indicates the number of pixels per second (px/s) on the x axis.public int getFlingDistanceY(int velocityY)
velocityY - Indicates the number of pixels per second (px/s) on the y axis.public int getFlingVelocityX()
public int getFlingVelocityY()
public void startScroll(int startX,
int startY,
int dx,
int dy)
startX - Indicates the X-axis coordinate of the start point to scroll.startY - Indicates the Y-axis coordinate of the start point to scroll.dx - Indicates the scrolling distance on X-axis. If the value is positive, the content scrolls to the
left. If the value is negative, the content scrolls to the right.dy - Indicates the scrolling distance on Y-axis. If the value is positive, the content scrolls up. If
the value is negative, the content scrolls down.public int getHorizontalBeginPosition()
public int getScrollDistanceX()
public int getScrollDistanceY()
public int getCurrValue(int direction)
direction - Indicate x-axis or y-axis.public boolean isFinished()
true if scrolling or flinging is finished; returns false otherwise.public void setFriction(float friction)
friction - Indicates the amount of friction.public float getFriction()
public void abortAnimation()
public boolean updateScroll()
After the animation position is updated, the animation update result is returned.
true if the animation is updated; returns false otherwise.public float getCurrVelocity()
public boolean isOverScrolled()
true if the content has scrolled to a valid position; returns false otherwise.