Beheer dia‑overgangen in presentaties op Android
Overzicht
Slide transitions control how slides appear during a slide show. With Aspose.Slides for Android via Java, you can choose a transition effect for each slide, configure advancement by mouse click or timer, and adjust options specific to an effect. This article uses Java examples to apply transitions, set exact transition durations, manage slide timing, and create a Morph transition between two slides. The examples also show how to save the settings to a PPTX file.
Dia‑overgang toevoegen
To apply a transition, load a presentation with the Presentation class and access the slide’s transition settings through getSlideShowTransition. Use setType with a value from the TransitionType enumeration, then save the presentation.
The following example applies a Circle transition to the first slide and a Comb transition to the second. Use an input.pptx file with at least two slides.
import com.aspose.slides.*;
Presentation presentation = new Presentation("input.pptx");
try {
if (presentation.getSlides().size() >= 2) {
presentation.getSlides().get_Item(0).getSlideShowTransition().setType(TransitionType.Circle);
presentation.getSlides().get_Item(1).getSlideShowTransition().setType(TransitionType.Comb);
presentation.save("slide-transitions.pptx", SaveFormat.Pptx);
} else {
System.out.println("The input presentation must contain at least two slides.");
}
} finally {
presentation.dispose();
}
Geavanceerde dia‑overgang toevoegen
You can configure how long a slide remains on screen and whether a mouse click advances the slide show. The following methods control this behavior:
- setAdvanceOnClick laat de kijker vooruitgaan door te klikken met de muis.
- setAdvanceAfter schakelt automatische voortzetting in.
- setAdvanceAfterTime specificeert de vertraging vóór automatische voortzetting, in milliseconden.
Enable both click and timed advancement to let the viewer move on with a click or wait for the timer. To use only the timer, pass false to setAdvanceOnClick. The delay controls when the slide show advances; it does not set the duration of the visual transition effect.
This example assigns different effects to the first three slides and enables automatic advancement after 3, 5, and 7 seconds, respectively. Mouse clicks can also advance these slides. Use an input.pptx file with at least three slides.
import com.aspose.slides.*;
Presentation presentation = new Presentation("input.pptx");
try {
if (presentation.getSlides().size() >= 3) {
ISlideShowTransition firstTransition = presentation.getSlides().get_Item(0).getSlideShowTransition();
firstTransition.setType(TransitionType.Circle);
firstTransition.setAdvanceOnClick(true);
firstTransition.setAdvanceAfter(true);
firstTransition.setAdvanceAfterTime(3000);
ISlideShowTransition secondTransition = presentation.getSlides().get_Item(1).getSlideShowTransition();
secondTransition.setType(TransitionType.Comb);
secondTransition.setAdvanceOnClick(true);
secondTransition.setAdvanceAfter(true);
secondTransition.setAdvanceAfterTime(5000);
ISlideShowTransition thirdTransition = presentation.getSlides().get_Item(2).getSlideShowTransition();
thirdTransition.setType(TransitionType.Zoom);
thirdTransition.setAdvanceOnClick(true);
thirdTransition.setAdvanceAfter(true);
thirdTransition.setAdvanceAfterTime(7000);
presentation.save("advanced-transitions.pptx", SaveFormat.Pptx);
} else {
System.out.println("The input presentation must contain at least three slides.");
}
} finally {
presentation.dispose();
}
To check whether timed advancement is enabled, call getAdvanceAfter. A stored delay alone does not indicate that the timer is active.
The next example opens the file saved above, reports each enabled timer, and disables automatic advancement for slides with a delay greater than two seconds. It enables mouse clicks for those slides and saves the updated settings.
import com.aspose.slides.*;
Presentation presentation = new Presentation("advanced-transitions.pptx");
try {
for (ISlide slide : presentation.getSlides()) {
ISlideShowTransition transition = slide.getSlideShowTransition();
if (transition.getAdvanceAfter()) {
System.out.println("Slide " + slide.getSlideNumber() + ": advance after " + transition.getAdvanceAfterTime() + " ms.");
if (transition.getAdvanceAfterTime() > 2000) {
transition.setAdvanceAfter(false);
transition.setAdvanceOnClick(true);
}
}
}
presentation.save("adjusted-transitions.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
Precisie bij timing van overgangen
Use setDuration to specify the exact length of a transition effect in milliseconds. The slide’s getSlideShowTransition method exposes these settings through ISlideShowTransition:
| Methode | Doel |
|---|---|
| setDuration | Stelt de duur van het overgangseffect zelf in, in milliseconden. |
| setAdvanceAfterTime | Stelt de vertraging in vóór dat de dia automatisch wordt voortgezet, in milliseconden. Geef true door aan setAdvanceAfter om deze timer te activeren. |
| setSpeed | Selecteert een vooraf gedefinieerde snelheidscategorie uit TransitionSpeed: Slow, Medium, of Fast. Het wordt gebruikt wanneer geen exacte duur is gespecificeerd. |
[setDuration] controls only the transition effect; it does not determine how long the slide remains visible. Configure the automatic advancement delay separately. When no explicit duration is set, Aspose.Slides determines the effect duration from the transition type and the getSpeed value.
Zelfde duur toepassen op elke dia
For consistent pacing, apply the same effect and exact duration to every slide. This example loads input.pptx, selects Fade from TransitionType, and gives each transition a duration of 750 milliseconds. It separately enables automatic advancement after 5,000 milliseconds and disables advancement by mouse click, then saves the result as PPTX.
import com.aspose.slides.*;
Presentation presentation = new Presentation("input.pptx");
try {
for (ISlide slide : presentation.getSlides()) {
ISlideShowTransition transition = slide.getSlideShowTransition();
transition.setType(TransitionType.Fade);
transition.setDuration(750);
// Configureer automatische voortzetting, onafhankelijk van de duur van het effect.
transition.setAdvanceAfter(true);
transition.setAdvanceAfterTime(5000);
transition.setAdvanceOnClick(false);
}
presentation.save("precise-transitions.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
Verschillende duur instellen per individuele dia
Different slides can use different effect durations. For example, use a brief transition for a title slide and a longer transition for a section introduction. This example sets 500 milliseconds for the first slide and 1,200 milliseconds for the second. Use an input.pptx file with at least two slides.
import com.aspose.slides.*;
Presentation presentation = new Presentation("input.pptx");
try {
if (presentation.getSlides().size() >= 2) {
ISlideShowTransition firstTransition = presentation.getSlides().get_Item(0).getSlideShowTransition();
firstTransition.setType(TransitionType.Fade);
firstTransition.setDuration(500);
ISlideShowTransition secondTransition = presentation.getSlides().get_Item(1).getSlideShowTransition();
secondTransition.setType(TransitionType.Push);
secondTransition.setDuration(1200);
presentation.save("individual-transition-durations.pptx", SaveFormat.Pptx);
} else {
System.out.println("The input presentation must contain at least two slides.");
}
} finally {
presentation.dispose();
}
Overgangen afstemmen op geanimeerde uitvoer
When preparing an animated GIF, HTML5 presentation, or video, set exact transition durations before export to match the intended pacing. For example, use a 600-millisecond fade between scenes, and adjust each slide’s advancement delay separately to allow time for its narration or content.
For GIF and video, coordinate the output frame rate with the effect duration: 600 milliseconds corresponds to 18 frames at 30 frames per second. In HTML5, enable animated transitions in the export settings. Check the chosen export format’s supported effects and timing options, and preview the output to confirm synchronization.
Bestaande overgangsduur lezen
Call getDuration before modifying the transition to determine whether an explicit value is stored. A value of -1 means no explicit duration is set; a nonnegative value specifies the stored duration in milliseconds. The unset value is not the calculated playback duration: Aspose.Slides uses the transition type and the getSpeed value to determine that duration. Setting a transition type can initialize a duration, so inspect the original settings first.
import com.aspose.slides.*;
Presentation presentation = new Presentation("input.pptx");
try {
for (ISlide slide : presentation.getSlides()) {
ISlideShowTransition transition = slide.getSlideShowTransition();
int duration = transition.getDuration();
if (duration >= 0) {
System.out.println("Slide " + slide.getSlideNumber() + ": stored transition duration is " + duration + " ms.");
} else {
System.out.println("Slide " + slide.getSlideNumber() + ": no explicit duration; timing depends on transition type " + transition.getType() + " and speed " + transition.getSpeed() + ".");
}
}
} finally {
presentation.dispose();
}
Morph‑overgang
The Morph transition animates changes between objects on consecutive slides. To create a simple Morph effect, clone a slide, move or resize an object on the clone, and apply the Morph transition to the second slide. This gives the transition corresponding objects to animate between their original and modified states.
The following example creates a slide with a text rectangle, clones the slide, and changes the rectangle’s position and size on the clone. It then selects Morph from the TransitionType enumeration for the second slide. Open the saved file in a presentation viewer that supports Morph to see the effect during a slide show.
import com.aspose.slides.*;
Presentation presentation = new Presentation();
try {
ISlide firstSlide = presentation.getSlides().get_Item(0);
IAutoShape rectangle = firstSlide.getShapes().addAutoShape(ShapeType.Rectangle, 100, 100, 400, 100);
rectangle.getTextFrame().setText("Morph transition");
ISlide secondSlide = presentation.getSlides().addClone(firstSlide);
IShape movedRectangle = secondSlide.getShapes().get_Item(0);
movedRectangle.setX(movedRectangle.getX() + 100);
movedRectangle.setY(movedRectangle.getY() + 50);
movedRectangle.setWidth(movedRectangle.getWidth() - 200);
movedRectangle.setHeight(movedRectangle.getHeight() - 10);
secondSlide.getSlideShowTransition().setType(TransitionType.Morph);
presentation.save("morph-transition.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
Morph‑overgangstypen
The TransitionMorphType enumeration controls how Morph matches and animates content:
- ByObject behandelt elke vorm als één geheel.
- ByWord animeert tekst door woorden te matchen waar mogelijk.
- ByChar animeert tekst door karakters te matchen waar mogelijk.
Use setType to select Morph before accessing getValue. The value then provides the IMorphTransition interface, whose setMorphType method selects the matching mode.
This example opens the presentation created in the previous section and configures the second slide to use word-based Morph animation.
import com.aspose.slides.*;
Presentation presentation = new Presentation("morph-transition.pptx");
try {
if (presentation.getSlides().size() >= 2) {
ISlideShowTransition transition = presentation.getSlides().get_Item(1).getSlideShowTransition();
transition.setType(TransitionType.Morph);
ITransitionValueBase transitionValue = transition.getValue();
if (transitionValue instanceof IMorphTransition) {
IMorphTransition morphTransition = (IMorphTransition) transitionValue;
morphTransition.setMorphType(TransitionMorphType.ByWord);
presentation.save("morph-by-word.pptx", SaveFormat.Pptx);
} else {
System.out.println("Morph transition options are unavailable.");
}
} else {
System.out.println("The input presentation must contain at least two slides.");
}
} finally {
presentation.dispose();
}
Overgangseffecten instellen
Some transitions expose additional options, such as direction or whether the effect starts from a black screen. The available options depend on the transition selected with setType. Set the type first, then use the appropriate interface from getValue.
The following example applies a Cut transition to the first slide of input.pptx. It calls setFromBlack through IOptionalBlackTransition so that the transition starts from a black screen.
import com.aspose.slides.*;
Presentation presentation = new Presentation("input.pptx");
try {
ISlideShowTransition transition = presentation.getSlides().get_Item(0).getSlideShowTransition();
transition.setType(TransitionType.Cut);
ITransitionValueBase transitionValue = transition.getValue();
if (transitionValue instanceof IOptionalBlackTransition) {
IOptionalBlackTransition cutTransition = (IOptionalBlackTransition) transitionValue;
cutTransition.setFromBlack(true);
presentation.save("cut-from-black.pptx", SaveFormat.Pptx);
} else {
System.out.println("Cut transition options are unavailable.");
}
} finally {
presentation.dispose();
}
FAQ
Kan ik de afspeelsnelheid van een dia‑overgang regelen?
Ja. Geef de voorkeur aan setDuration wanneer je een exacte effectduur in milliseconden nodig hebt. Gebruik setSpeed wanneer een vooraf gedefinieerde TransitionSpeed‑categorie—Slow, Medium of Fast—volstaat en er geen expliciete duur is ingesteld. Deze instellingen regelen het overgangseffect onafhankelijk van de vertraging voor automatische voortzetting.
Kan ik audio aan een overgang koppelen en laten herhalen?
Ja. Wijs ingesloten audio toe met setSound, geef StartSound uit de enumeratie TransitionSoundMode door aan setSoundMode, en schakel setSoundLoop in met true. De audio wordt herhaald tot het volgende geluidsevent in de diavoorstelling.
Wat is de snelste manier om dezelfde overgang op elke dia toe te passen?
Loop door de getSlides‑collectie van de presentatie en roep setType aan met dezelfde waarde voor de overgang van elke dia. Stel eventuele timing‑ en effectopties in dezelfde lus in om het gedrag consistent te houden over alle dia’s.
Hoe kan ik controleren welke overgang momenteel op een dia is ingesteld?
Roep getType aan op het resultaat van getSlideShowTransition van de dia. Het retourneert een waarde uit de TransitionType‑enumeratie; None betekent dat er geen overgangseffect is toegepast.