til
til copied to clipboard
RxView.globalLayouts RxView.globalLayouts replace addOnGlobalLayoutListener
Khi ta cần detect layout change trước đây ta thường dùng
myView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
}
});
Chúng ta có thể dùng RxView để làm việc này 1 cách dễ dàng hơn:
RxView.globalLayouts(info_overlay)
.map { info_overlay.visibility }
.distinct()
.subscribe { newVisibility ->
}
hoặc
RxView.layoutChanges(view)
.distinct()
.subscribe { newVisibility ->
}