Skip to content
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

Particle System does not show in a Fragment #92

Open
JohnMerlino2 opened this issue Feb 10, 2018 · 5 comments
Open

Particle System does not show in a Fragment #92

JohnMerlino2 opened this issue Feb 10, 2018 · 5 comments

Comments

@JohnMerlino2
Copy link

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?

@MahmoudMabrok
Copy link

i face same problem

@MahmoudMabrok
Copy link

MahmoudMabrok commented May 29, 2020

Solution is to delay action of generating particles
i used this Handler().postDelayed({ stratAnim() }, 1200) with kotlin

@plattysoft
Copy link
Owner

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 #22

@MahmoudMabrok
Copy link

@plattysoft why not make it as internal implementation of lib to start anim when views are measured

@plattysoft
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants