Comments (4)
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: http://stackoverflow.com/questions/3779173/determining-the-size-of-an-android-view-at-runtime
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
from leonids.
Thanks for your help, that works with the ViewTreeObserver ;)
from leonids.
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 View.post(Runnable) or View.postDelayed(Runnable) method. This fixed the issue of particales whithout onclick for me.
findViewById(R.id.center_anchor).post(new Runnable() {
@OverRide
public void run() {
new ParticleSystem(ModeSelectionActivity.this, 100, R.drawable.ic_gem_green, 30000)
.setSpeedRange(0.2f, 0.5f)
.oneShot(findViewById(R.id.center_anchor), 100);
}
});
If this helps out, Good Luck :)
from leonids.
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.
from leonids.
Related Issues (20)
- 为什么用不了呀
- EmiterWithGravityExampleActivity ,How to make particles fly upward? HOT 1
- How to change TIMER_TASK_INTERVAL? HOT 2
- OneShot method doesn't call onDraw(); HOT 2
- Particle slowdown (air resistance)
- Copyright statement missing
- How to change the direction of the animation
- Use Leonids as a shared transition view HOT 1
- Emitters freeze after several seconds when built from latest tools HOT 3
- Particle Wall HOT 1
- Reverse Animation
- Rootview elevation HOT 2
- Bug causing crash
- Bug causing crash HOT 3
- JCenter shutdown HOT 5
- Top !!
- Typo in ParticleSystem class HOT 1
- Crash detected in onUpdate(long miliseconds) function
- java.lang.NullPointerException
- NPE HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from leonids.