Closed wmhtet closed 7 years ago
You need to create the particle system after the views are measured, see https://github.com/plattysoft/Leonids/issues/22
Thanks for the nice job on this library. I have followed the link and now I am using the following code to address the issue.
final View rootView = findViewById(android.R.id.content);
ViewTreeObserver viewTreeObserver = rootView.getViewTreeObserver();
if (viewTreeObserver.isAlive()) {
viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
rootView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
new ParticleSystem(WelcomeActivity.this, 80, R.drawable.confeti2, 10000)
.setSpeedModuleAndAngleRange(0f, 0.1f, 180, 180)
.setRotationSpeed(144)
.setAcceleration(0.000017f, 90)
.emit(findViewById(R.id.emiter_top_right), 8);
new ParticleSystem(WelcomeActivity.this, 80, R.drawable.confeti3, 10000)
.setSpeedModuleAndAngleRange(0f, 0.1f, 0, 0)
.setRotationSpeed(144)
.setAcceleration(0.000017f, 90)
.emit(findViewById(R.id.emiter_top_left), 8);
}
});
Can I commit the following two codes? It requires min SDK to increase to 16 tho.
<?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/confetti_layer">
<View android:id="@+id/emiter_top_left"
android:layout_gravity="top|left"
android:layout_marginTop="-20dp"
android:layout_width="1dp"
android:layout_height="1dp" />
<View android:id="@+id/emiter_top_right"
android:layout_gravity="top|right"
android:layout_marginTop="-20dp"
android:layout_width="1dp"
android:layout_height="1dp" />
</FrameLayout>
<TextView
android:text="@string/app_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Base.TextAppearance.AppCompat.Large"
android:layout_gravity="center"/>
package com.plattysoft.leonids.examples;
import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.ViewTreeObserver;
import com.plattysoft.leonids.ParticleSystem;
public class OnCreateBehindLayerActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_on_create_behind_layer);
final View rootView = findViewById(android.R.id.content);
ViewTreeObserver viewTreeObserver = rootView.getViewTreeObserver();
if (viewTreeObserver.isAlive()) {
viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
rootView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
new ParticleSystem(OnCreateBehindLayerActivity.this, 80, R.drawable.confeti2, 10000, R.id.confetti_layer)
.setSpeedModuleAndAngleRange(0f, 0.1f, 180, 180)
.setRotationSpeed(144)
.setAcceleration(0.000017f, 90)
.emit(findViewById(R.id.emiter_top_right), 8);
new ParticleSystem(OnCreateBehindLayerActivity.this, 80, R.drawable.confeti3, 10000, R.id.confetti_layer)
.setSpeedModuleAndAngleRange(0f, 0.1f, 0, 0)
.setRotationSpeed(144)
.setAcceleration(0.000017f, 90)
.emit(findViewById(R.id.emiter_top_left), 8);
}
});
}
}
}
how to stop after one time play?
@bassam2 I assume you are asking about using oneShot instead of emitter, but commenting on an unrelated issue in confusing at the very least.
Hello @plattysoft Thank you for your reply & support no I am asking about Confetti I want to stop after one count play thanks
@bassam2 this issue is about not starting from the proper place. You are asking for how to use the library in an issue, which is supposed to be a defect, that's why it is unrelated. Anyway, you either want to use oneShot as I suggested or use a timer and call stopEmitting.
Somehow, both confetti only come from the top left even though the view emiter is properly on left and right of screen top in layout file. Swapping the two ParticleSystem constructors to see if the later constructor(left) is overriding the former constructor(right). It is not the case. For now, I have change the min/max angle to have spread out confetti