定位纸屑 [英] Positioning confetti

查看:122
本文介绍了定位纸屑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在按照下面的教程添加纸屑.

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.

希望有帮助....

这篇关于定位纸屑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆