Usage Guide
Pulsator4Droid offers a range of customization options, both in your XML layouts and programmatically in your Java or Kotlin code.
XML Attributes
You can configure the PulsatorLayout
directly in your layout files using the following attributes. Remember to add the app
namespace to your root layout: xmlns:app="http://schemas.android.com/apk/res-auto"
.
Attribute | Type | Description |
---|---|---|
app:pulse_count |
integer | The number of pulse circles to display simultaneously. Default is 4 . |
app:pulse_duration |
integer | The duration in milliseconds for a single pulse wave to expand and fade out. Default is 7000 . |
app:pulse_repeat |
integer | The number of times the animation should repeat. Set to 0 for infinite repeats. Default is 0 . |
app:pulse_color |
color | The ARGB color of the pulse waves. Default is Color.rgb(0, 116, 193) . |
app:pulse_startFromScratch |
boolean | If true , the animation starts with all waves from the center. If false , waves start spread out as if the animation had already been running. Default is true . |
app:pulse_interpolator |
enum | The animation interpolator, which controls the rate of change of the animation. Accepted values are Linear , Accelerate , Decelerate , and AccelerateDecelerate . Default is Linear . |
Example
<pl.bclogic.pulsator4droid.library.PulsatorLayout
android:id="@+id/pulsator"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:pulse_count="6"
app:pulse_duration="4000"
app:pulse_repeat="0"
app:pulse_color="#FF4081"
app:pulse_interpolator="Decelerate">
<!-- Your centered view here -->
</pl.bclogic.pulsator4droid.library.PulsatorLayout>
Programmatic Control
You can also control and customize the PulsatorLayout
at runtime.
Controlling the Animation
start()
: Starts the animation.stop()
: Stops the animation.isStarted()
: Returnstrue
if the animation is currently running.
PulsatorLayout pulsator = (PulsatorLayout) findViewById(R.id.pulsator);
// To start
pulsator.start();
// To stop
if (pulsator.isStarted()) {
pulsator.stop();
}
Customizing Appearance and Behavior
These methods allow you to change the animation's properties dynamically. Calling any of these will reset and rebuild the animation with the new values.
setCount(int count)
: Sets the number of pulse waves.setDuration(int millis)
: Sets the duration of a single pulse wave in milliseconds.setRepeat(int repeat)
: Sets the number of repeats (0
for infinite).setColor(int color)
: Sets the color of the pulse waves.setInterpolator(int type)
: Sets the animation interpolator using the constants provided (e.g.,PulsatorLayout.INTERP_ACCELERATE
).
// Example: Make the pulse faster and change its color
pulsator.setDuration(2000);
pulsator.setColor(Color.parseColor("#00FF00"));
pulsator.setCount(3);