New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Particles without onclick call Example #22

leglopy opened this Issue Jun 28, 2015 · 4 comments


None yet
3 participants
Copy link

leglopy commented Jun 28, 2015


I'm using this wonderful library but i'm blocked to animate particles without a touch on a button.

I have a Xml view with

<RelativeLayout xmlns:android=""
    xmlns:tools="" android:layout_width="match_parent"
    android:layout_height="match_parent"  tools:context=".MainActivity"
        android:layout_centerHorizontal="true" />

And an actvity with

    public void buttonTouched(View v){

 public void doAnimation(){
            ParticleSystem ps = new ParticleSystem(this, 50, R.drawable.placeholder, 1000,;
            ps.setSpeedRange(0.1f, 0.25f);
            ps.setScaleRange(0.7f, 1.3f);
            ps.setSpeedRange(0.1f, 0.25f);
            ps.setAcceleration(0.0001f, 90);
            ps.setRotationSpeedRange(90, 180);
            ps.setFadeOut(200, new AccelerateInterpolator());
            ps.emit(v, 100);

That code is okay. I have particles around the button.
But if i start the animation programatically without onclick event I have the animation in the top left corner --'

 protected void onStart() {

It's the same with

 protected void onStart() {

Thank you in advance for any help you can provide


This comment has been minimized.

Copy link

plattysoft commented Jun 28, 2015

This is duplication of #21, but at least your title and code explanation is much more detailed and clear. Actually it is a great report.

I'm doing a copy and paste from the other ticket:

It is due to how Android works.

For the particle system to work fine, the views must be measured when it is created. Inside onCreate the Views are not yet measured, just created. You need to set a ViewTreeObserver to know when the layout has been measured.

This is a standard question on Android, check out this link on Stack Overflow, it is exactly the same problem:

That being said, I'd leave this one open because I want to improve the code so this special case can be done automatically. I'm afraid that, in the meantime, you need to go with the ViewTreeObserver


This comment has been minimized.

Copy link

leglopy commented Jun 30, 2015

Thanks for your help, that works with the ViewTreeObserver ;)


This comment has been minimized.

Copy link

rishirajput commented May 17, 2018

Hey, I was also having a problem with all particles showing up on top left corner regardless of anchor view positions on launch. The problem was the anchor view was not ready while starting the animation. So you can put the animation code inside or View.postDelayed(Runnable) method. This fixed the issue of particales whithout onclick for me.

findViewById( Runnable() {
public void run() {
new ParticleSystem(ModeSelectionActivity.this, 100, R.drawable.ic_gem_green, 30000)
.setSpeedRange(0.2f, 0.5f)
.oneShot(findViewById(, 100);

If this helps out, Good Luck :)


This comment has been minimized.

Copy link

plattysoft commented May 17, 2018

Posting a runnable, even with a delay does not guarantee a fix. You need to start the emitter after the views have been measured. Posting a runnable is a gamble that works 99.9% of the time, but if the phone is slow for whatever reason, it will not work.
The only way to make sure it works is the tree observer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment