Ela*_*nda 9 layout android view robolectric layout-inflater
我有一个要测试的android customView。
当N为subView高度时,很少有测试能够模拟N dps的滚动。
我使用robolectric运行测试,但是我总是在运行时获得 subView.getHeight() == 0
这是因为subView的高度定义为wrap_content,我想robolectric不会使所有视图膨胀以获取此准确信息。
例如,subView.getWidth > 0按定义为match parent。
这是我的测试@before方法:
@Before
public void setUp() {
myView.getHeaderView().getViewTreeObserver().addOnGlobalLayoutListener(
new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
myHeight =
myView.getHeaderView().getHeight();
}
});
activityScenarioRule
.getScenario()
.onActivity(activity -> activity.setContentView(myView));
activityScenarioRule.getScenario().moveToState(State.RESUMED);
}
Run Code Online (Sandbox Code Playgroud)
在测试运行时如何仍然获得包装内容的高度?
该代码确实调用onGlobalLayout但返回height==0