@Test public void whenMeasuredCallOnMeasured() { whenMeasured(view, new OnMeasured() { @Override public void onMeasured() { onMeasuredCalled = true; } }); activity.setContentView(view); assertThat(onMeasuredCalled).isTrue(); }
static void whenMeasured(final View view, final OnMeasured onMeasured) { int width = view.getWidth(); int height = view.getHeight(); if (width > 0 && height > 0) { onMeasured.onMeasured(); return; } view.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { final ViewTreeObserver observer = view.getViewTreeObserver(); if (observer.isAlive()) { observer.removeOnPreDrawListener(this); } onMeasured.onMeasured(); return true; } }); }
Views { static void whenMeasured(final View view, final OnMeasured onMeasured) { int width = view.getWidth(); int height = view.getHeight(); if (width > 0 && height > 0) { onMeasured.onMeasured(); return; } view.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { final ViewTreeObserver observer = view.getViewTreeObserver(); if (observer.isAlive()) { observer.removeOnPreDrawListener(this); } onMeasured.onMeasured(); return true; } }); } }
Views { static void whenMeasured(final View view, final OnMeasured onMeasured) { int width = view.getWidth(); int height = view.getHeight(); if (width > 0 && height > 0) { onMeasured.onMeasured(); return; } view.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { final ViewTreeObserver observer = view.getViewTreeObserver(); if (observer.isAlive()) { observer.removeOnPreDrawListener(this); } onMeasured.onMeasured(); return true; } }); } private  Views(); }
Views { static void whenMeasured(final View view, final OnMeasured onMeasured) { int width = view.getWidth(); int height = view.getHeight(); if (width > 0 && height > 0) { onMeasured.onMeasured(); return; } view.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { final ViewTreeObserver observer = view.getViewTreeObserver(); if (observer.isAlive()) { observer.removeOnPreDrawListener(this); } onMeasured.onMeasured(); return true; } }); } private  Views();  }
Views { static void whenMeasured(final View view, final OnMeasured onMeasured) { int width = view.getWidth(); int height = view.getHeight(); if (width > 0 && height > 0) { onMeasured.onMeasured(); return; } view.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { final ViewTreeObserver observer = view.getViewTreeObserver(); if (observer.isAlive()) { observer.removeOnPreDrawListener(this); } onMeasured.onMeasured(); return true; } }); } private  Views();   }