plattysoft / Leonids

A Particle System for standard Android UI: http://plattysoft.github.io/Leonids/
Apache License 2.0
2.28k stars 398 forks source link

Example of particle system on the background #88

Open nikolaGithub2018 opened 6 years ago

nikolaGithub2018 commented 6 years ago

If we have for example, some layout like this: < ScrollView > < LinearLayout > -Button0 -Button1 -Button2 -Button3 ... < / LinearLayout > </ ScrollView >

How to set ParticleSystem constructor which will emit particles behind all those buttons (I need particles to show only in background, not to fall in front of buttons)???

this will not work> ParticleSystem(activity, maxParticles, drawableRedId, timeToLive, idOfLinearLayoutFromExampleAbove)

plattysoft commented 6 years ago

The anchor view for the particle system is the one that will be used as a parent for the particle system, if you want it to be on the background you need something like this:

<FrameLayout>
 <your layout />
</FrameLayout>

And make the FrameLayout be the anchor. I may need to check if the Particle system is added as a child at the end or at the beginning, to be sure, you can have another FrameLayout to be the first child of the FrameLayout and use that one as the anchor

nikolaGithub2018 commented 6 years ago

Thanks for fast reply, I really appreciate it. I tried that and it did not work, although I am not sure I understood your post entirely. Would you mind to write the exact constructor call for layout below:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/frame_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ScrollView
        android:id="@+id/scroll_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:id="@+id/linear_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            >

            <Button
                android:id="@+id/button0"
                ...
                />

        </LinearLayout>
    </ScrollView>
</FrameLayout>

Thanks man ;)

plattysoft commented 6 years ago

Try adding another FrameLayout before the ScrollView and using that one as an anchor, that should work (I mentioned it briefly on my previous comment, I didn't remember how it was implemented 100%)

nikolaGithub2018 commented 6 years ago

Great, it works :) Just call
new ParticleSystem(this, 80, bitmap, 10000, R.id.frame_anim_background) with this layout:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

      <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/frame_anim_background">
      </FrameLayout>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            >

            <Button
                android:id="@+id/button0"
                ...
                />

        </LinearLayout>
    </ScrollView>
</FrameLayout>