Closed brittle123 closed 3 years ago
Hi @brittle123,
This issue is a duplicate of:
When starting Konfetti make sure the layout is properly initialized. This can be done by registering a GlobalLayoutListener on the ViewTreeObserver for example.
Thanks but using postdelay it works for me.
The following part of the code:
final KonfettiView konfettiView = findViewById(R.id.viewKonfetti);
konfettiView.build()
.addColors(Color.YELLOW, Color.GREEN, Color.MAGENTA)
.setDirection(0.0, 359.0)
.setSpeed(1f, 5f)
.setFadeOutEnabled(true)
.setTimeToLive(2000L)
.addShapes(Shape.Square.INSTANCE, Shape.Circle.INSTANCE)
.addSizes(new Size(12, 5f))
.setPosition(-50f, konfettiView.getWidth() + 50f, -50f, -50f)
.streamFor(300, 3000L);
Needs to be executed when the layout is fully drawn. There are different ways to doing this. For example with an OnGlobalLayoutListener like here: https://stackoverflow.com/a/14298483
Haven't tested it but that would become something like:
final KonfettiView konfettiView = findViewById(R.id.viewKonfetti);
konfettiView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
konfettiView.build()
.addColors(Color.YELLOW, Color.GREEN, Color.MAGENTA)
.setDirection(0.0, 359.0)
.setSpeed(1f, 5f)
.setFadeOutEnabled(true)
.setTimeToLive(2000L)
.addShapes(Shape.Square.INSTANCE, Shape.Circle.INSTANCE)
.addSizes(new Size(12, 5f))
.setPosition(-50f, konfettiView.getWidth() + 50f, -50f, -50f)
.streamFor(300, 3000L);
}
});
Hello Sir!,.. i've used your simple approach but it starts konfetti from top left corner. i want it to display from top not only from top corner.Here are my both xml and java code. don't know why it's showing me like this. Please help me ASAP! Thanks and Regards.
SceenShot