Skip to content
This repository has been archived by the owner on Aug 5, 2022. It is now read-only.
Thomas Orlando edited this page Jul 4, 2020 · 11 revisions

Frequently Asked Questions

My particles are always shown in the top left corner, what is going on?

It is due to how Android works.

For the particle system to function correctly, it's anchor view must already be measured when it is created by ParticleSystem.emit() or ParticleSystem.oneShot(). Inside onCreate() or onStart(), the views are not yet measured, meaning that while instances of ParticleSystem can be created by those methods, calling emit() or oneShot() from inside them will cause the particle system to always appear in the top left corner.

To fix this issue, a ViewTreeObserver can be used to start the particle system when the layout has been measured:

Java

ViewTreeObserver viewTreeObserver = view.getViewTreeObserver();
if (viewTreeObserver.isAlive()) {
    viewTreeObserver.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            // Remove the layout listener if you only want to shoot/emit once
            view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            
            // START PARTICLE SYSTEMS HERE:
            // ...
        }
    });
}

Kotlin

val viewTreeObserver = view.viewTreeObserver
if (viewTreeObserver.isAlive) {
    viewTreeObserver.addOnGlobalLayoutListener(object : OnGlobalLayoutListener {
        override fun onGlobalLayout() {
            // Remove the layout listener if you only want to shoot/emit once
            view.viewTreeObserver.removeOnGlobalLayoutListener(this)

            // START PARTICLE SYSTEMS HERE:
            // ...
        }
    })
}

This is a standard issue on Android; for further information check out this question on Stack Overflow or Leonids issue #22.

Clone this wiki locally