我想对列表的每一项执行操作符。当前一项的操作完成时,应该触发列表的下一项。此时(见代码),对所有并行项执行运算符。如何避免并行处理?
List<String> strings = new ArrayList<>(3);
strings.add("String1");
strings.add("String2");
strings.add("String3");
Observable<String> stringObservables = Observable.from(strings);
stringObservables
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.lift(new TranslateViewOperator( ... parameters ... ))
.subscribe();
操作符定义如下:
public class TranslateViewOperator implements Observable.Operator<View, View> {
long duration;
Interpolator interpolator;
int runningAnimations;
float xTransform;
public TranslateViewOperator(float xTransform, long duration, Interpolator interpolator) {
super();
this.duration = duration;
this.interpolator = interpolator;
this.xTransform = xTransform;
}
@Override
public Subscriber<? super View> call(final Subscriber<? super View> subscriber) {
return new Subscriber<View>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(View view) {
runningAnimations++;
System.out.println("TranslateViewOperator.onNext");
ViewCompat.animate(view)
.translationX(xTransform - runningAnimations)
.scaleX(1f)
.scaleY(1f)
.setStartDelay(1000)
.setDuration(1000)
.setInterpolator(interpolator)
.withEndAction(() -> {
System.out.println("Animation finished");
});
}
};
}
}
println输出如下:
TranslateViewOperator.onNext
TranslateViewOperator.onNext
TranslateViewOperator.onNext
Animation finished
Animation finished
Animation finished
这意味着首先所有动画都在这里开始。但是我想在上一个动画完成后开始下一个动画
您正在寻找绑定。bindContent (list1用于);
在JavaFX中可用。
生成{@link javafx.collections之间的内容绑定。{@link java.util.List}.
如果{@code ObservableList}的内容发生了变化,{@code List}也会自动更新。