问题描述
我正在按照下面的教程添加纸屑.
I am following the tutorial below to add confetti.
final KonfettiView konfettiView = (KonfettiView)findViewById(viewKonfetti);
konfettiView.build()
.addColors(Color.RED, Color.GREEN)
.setSpeed(1f, 5f)
.setFadeOutEnabled(true)
.setTimeToLive(2000L)
.addShapes(Shape.RECT, Shape.CIRCLE)
.setPosition(0f, -359f, -359f, 0f)
.stream(200, 5000L);
我希望五彩纸屑从右上角显示,而不是从左上角显示.我应该在setPosition
方法中输入什么值?这种方法如何运作?
I want the confetti to appear from top right corner instead of top left. What values should I put in the setPosition
method? How does this method work?
我正在关注 https://github.com/DanielMartinus/Konfetti ,但是有关方法和方法的信息并不多他们的参数.
I am following this https://github.com/DanielMartinus/Konfetti but there is not much information about the methods and their parameters.
推荐答案
以下是编辑代码,可为您提供所需的输出:
Here is the code on editing which yields you with the desired output:
fun setPosition(x: Float, y: Float): ParticleSystem {
location.setX(x)
location.setY(y)
return this
}
/**
* Set position range to emit particles from
* A random position on the x-axis between [minX] and [maxX] and y-axis between [minY] and [maxY]
* will be picked for each confetti.
* @param [maxX] leave this null to only emit from [minX]
* @param [maxY] leave this null to only emit from [minY]
*/
fun setPosition(minX: Float, maxX: Float? = null, minY: Float, maxY: Float? = null): ParticleSystem {
location.betweenX(maxX, maxX)
location.betweenY(minY, maxY)
return this
}
请参考此答案以组装/调整方向和坐标因此.
Refer this answer to assemble/adjust the orientation and co-ordinates accordingly.
也;如果您只想放置坐标;正如您所发现的,有一个类MotionEvent
具有getX()
和getY()
方法,这些方法返回相对于视图的坐标.
Also; if you want to put just the co-ordinates; there is a class MotionEvent
which has getX()
and getY()
methods which return the coordinates relative to the view, as you have discovered.
希望有帮助....
这篇关于定位纸屑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!