我有一些junit andorid测试代码:
@Rule
public final ActivityScenarioRule<AppCompatActivity> activityScenarioRule =
new ActivityScenarioRule<>(AppCompatActivity.class);
StandAloneAccountMenuView<FakeAccount> standAloneSupportSuperG = createAccountMenuView();
int mySize;
@Before
public void setUp() {
activityScenarioRule
.getScenario()
.onActivity(
activity -> activity.setContentView(myView));
myView
.getViewTreeObserver()
.addOnGlobalLayoutListener(
new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
mySize = myView.getHeaderView().getHeight();
//removeOnGlobalLayoutListener
}
});
activityScenarioRule.getScenario().moveToState(State.RESUMED);
}
但是我的测试代码在执行mySize = myView.getHeaderView().getHeight();
之前运行
在测试运行之前如何获得myView.getHeaderView().getHeight();