2017-09-02 17 views
1

我正在按照下面的教程添加五彩紙屑。定位五彩紙屑

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); 

我想紙屑到從右上角,而不是左上角出現。我應該在方法中輸入什麼值?這種方法如何工作?

我按照這https://github.com/DanielMartinus/Konfetti但沒有太多關於方法及其參數的信息。

+0

好吧,所以如果你會看'confetti.kt'文件;有你想要的方式可以幫助你的位置和編輯信息?看看它 – Mandy8055

回答

2

這裏是關於編輯代碼這產生您與所需的輸出:

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 
} 

參見this answer組裝/相應地調整方向和座標。

另外;如果你只想把座標放在一起;有一個類MotionEvent其中有getX()getY()方法,它們會返回相對於視圖的座標,就像您發現的那樣。

希望它有幫助....