Leonids
Leonids copied to clipboard
Particle System does not show in a Fragment
I have a fragment:
AnimationFragment.java
public class AnimationFragment extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.animation_fragment, container, false);
new ParticleSystem(getActivity(), 80, R.drawable.poop_emoji, 10000)
.setSpeedByComponentsRange(0f, 0f, 0.05f, 0.1f)
.setAcceleration(0.00005f, 90)
.emitWithGravity(view.findViewById(R.id.animationBox), Gravity.BOTTOM, 8);
return view;
}
}
I have a view in Fragment with animationBox id:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View android:id="@+id/animationBox"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Notice I initialized the ParticleSystem in onCreateView. When I run the app, nothing shows. Can the Particle System with with Fragments?
i face same problem
Solution is to delay action of generating particles
i used this Handler().postDelayed({ stratAnim() }, 1200)
with kotlin
That is not the best solution, this is most likely the same problem as for Activities regarding that while onCreate the views are not yet measured. The suggested solution is to observe the view tree .
For more details see https://github.com/plattysoft/Leonids/issues/22
@plattysoft why not make it as internal implementation of lib to start anim when views are measured
if you create the ParticleSystem after the views are measured, you can don't get a ViewTreeObserver callback, so the system does not know if the views are been measured yet, or if they have been measured before creating. This needs to be tied to the ActivityLifecycle, maybe using the lifecycle components it could be done.