Animation
Contents
[
Hide
]
This article demonstrates how to create simple animations and manage their sequence using Aspose.Slides for Android via Java.
Add an Animation
Create a rectangle shape and apply a fade effect triggered on click.
static void addAnimation() {
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 50, 50, 100, 100);
// Fade effect.
slide.getTimeline().getMainSequence().addEffect(
shape, EffectType.Fade, EffectSubtype.None, EffectTriggerType.OnClick
);
} finally {
presentation.dispose();
}
}
Access an Animation
Retrieve the first animation effect from the slide timeline.
static void accessAnimation() {
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 50, 50, 100, 100);
slide.getTimeline().getMainSequence().addEffect(
shape, EffectType.Fade, EffectSubtype.None, EffectTriggerType.OnClick);
// Access the first animation effect.
IEffect effect = slide.getTimeline().getMainSequence().get_Item(0);
} finally {
presentation.dispose();
}
}
Remove an Animation
Remove an animation effect from the sequence.
static void removeAnimation() {
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 50, 50, 100, 100);
IEffect effect = slide.getTimeline().getMainSequence().addEffect(
shape, EffectType.Fade, EffectSubtype.None, EffectTriggerType.OnClick);
// Remove the effect.
slide.getTimeline().getMainSequence().remove(effect);
} finally {
presentation.dispose();
}
}
Sequence Animations
Add multiple effects and demonstrate the order in which animations occur.
static void sequenceAnimations() {
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape shape1 = slide.getShapes().addAutoShape(ShapeType.Rectangle, 50, 50, 100, 100);
IAutoShape shape2 = slide.getShapes().addAutoShape(ShapeType.Ellipse, 200, 50, 100, 100);
ISequence sequence = slide.getTimeline().getMainSequence();
sequence.addEffect(shape1, EffectType.Fly, EffectSubtype.Bottom, EffectTriggerType.OnClick);
sequence.addEffect(shape2, EffectType.Fly, EffectSubtype.Bottom, EffectTriggerType.OnClick);
} finally {
presentation.dispose();
}
}