public class EdgeEffect
extends Object
| java.lang.Object | |
| android.widget.EdgeEffect | |
当用户滚动超过2D空间中的内容边界时,此类执行可滚动窗口小部件边缘处使用的图形效果。
EdgeEffect是有状态的。 使用EdgeEffect应该创建中要显示的效果,给它使用方法输入数据中的每个边缘一个实例定制窗口小部件onAbsorb(int) , onPull(float) ,和onRelease() ,并绘制使用效果draw(Canvas)在窗口小部件的重写draw(Canvas)方法。 如果isFinished()在绘制后返回false,则边缘效果的动画尚未完成,并且该小部件应安排另一个绘制过程以继续动画。
绘图时,小部件应首先绘制其主要内容和子视图,通常通过从重写的draw方法调用super.draw(canvas) 。 (这将调用onDraw并根据需要将绘图派发到子视图。)然后可以使用draw(Canvas)方法在视图的内容上绘制边缘效果。
Public constructors |
|
|---|---|
EdgeEffect(Context context) 构建一个适合所提供上下文的新主题的EdgeEffect。 |
|
公共方法(Public methods) |
|
|---|---|
boolean |
draw(Canvas canvas) 画到提供的画布上。 |
void |
finish() 立即完成当前动画。 |
int |
getColor() 在argb中返回此边缘效果的颜色。 |
int |
getMaxHeight() 在给定原始 |
boolean |
isFinished() 报告EdgeEffect的动画是否完成。 |
void |
onAbsorb(int velocity) 当效应以给定的速度吸收冲击时调用。 |
void |
onPull(float deltaDistance) 一个视图应该在用户将内容从边缘拉开时调用它。 |
void |
onPull(float deltaDistance, float displacement) 一个视图应该在用户将内容从边缘拉开时调用它。 |
void |
onRelease() 在被拉动后释放对象时调用。 |
void |
setColor(int color) 在argb中设置此边缘效果的颜色。 |
void |
setSize(int width, int height) 以像素为单位设置此边缘效果的大小。 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
EdgeEffect (Context context)
构建一个适合所提供上下文的新主题的EdgeEffect。
| 参数(Parameters) | |
|---|---|
context |
Context: Context used to provide theming and resource information for the EdgeEffect |
boolean draw (Canvas canvas)
画到提供的画布上。 假定画布已相应地旋转并且大小已设置。 效果将绘制从X = 0到X =宽度的整个宽度,从Y = 0开始并延伸到高度的一些因子<1.f。
| 参数(Parameters) | |
|---|---|
canvas |
Canvas: Canvas to draw into |
| 返回(Returns) | |
|---|---|
boolean |
true if drawing should continue beyond this frame to continue the animation |
int getColor ()
在argb中返回此边缘效果的颜色。
| 返回(Returns) | |
|---|---|
int |
The color of this edge effect in argb |
int getMaxHeight ()
在给定原始 input size ,返回边缘效应将绘制的最大高度。
| 返回(Returns) | |
|---|---|
int |
The maximum height of the edge effect |
boolean isFinished ()
报告EdgeEffect的动画是否完成。 如果在调用draw(Canvas)之后此方法返回false,则主机小部件应安排另一个绘制过程以继续动画。
| 返回(Returns) | |
|---|---|
boolean |
true if animation is finished, false if drawing should continue on the next frame. |
void onAbsorb (int velocity)
当效应以给定的速度吸收冲击时调用。 在投掷物到达滚动边界时使用。
当使用 Scroller或 OverScroller ,方法 getCurrVelocity将提供在此使用的合理近似值。
| 参数(Parameters) | |
|---|---|
velocity |
int: Velocity at impact in pixels per second. |
void onPull (float deltaDistance)
一个视图应该在用户将内容从边缘拉开时调用它。 这将更新当前视觉效果及其相关动画的状态。 在此之后,主机视图应始终为invalidate()并相应地绘制结果。
当拉伸点的位移 onPull(float, float)时,使用EdgeEffect的视图应该 onPull(float, float) 。
| 参数(Parameters) | |
|---|---|
deltaDistance |
float: Change in distance since the last call. Values may be 0 (no change) to 1.f (full length of the view) or negative values to express change back toward the edge reached to initiate the effect. |
void onPull (float deltaDistance,
float displacement)
一个视图应该在用户将内容从边缘拉开时调用它。 这将更新当前视觉效果及其相关动画的状态。 在此之后,主机视图应始终为invalidate()并相应地绘制结果。
| 参数(Parameters) | |
|---|---|
deltaDistance |
float: Change in distance since the last call. Values may be 0 (no change) to 1.f (full length of the view) or negative values to express change back toward the edge reached to initiate the effect. |
displacement |
float: The displacement from the starting side of the effect of the point initiating the pull. In the case of touch this is the finger position. Values may be from 0-1. |
void onRelease ()
在被拉动后释放对象时调用。 这将开始效果的“衰退”阶段。 调用此方法后,主机视图应为invalidate()并据此绘制结果。
void setColor (int color)
在argb中设置此边缘效果的颜色。
| 参数(Parameters) | |
|---|---|
color |
int: Color in argb |
void setSize (int width,
int height)
以像素为单位设置此边缘效果的大小。
| 参数(Parameters) | |
|---|---|
width |
int: Effect width in pixels |
height |
int: Effect height in pixels |