Android getMeasuredWidth()不工作
这段代码在我的Nexus7上运行不好。第一次安装(调试)时,它给了我价值 “1286”,但关闭应用程序后,我再次启动它,然后给我宽度“1542” 我知道这是一个正确的代码,但它不工作,为什么它给错误的值Android getMeasuredWidth()不工作,android,Android,这段代码在我的Nexus7上运行不好。第一次安装(调试)时,它给了我价值 “1286”,但关闭应用程序后,我再次启动它,然后给我宽度“1542” 我知道这是一个正确的代码,但它不工作,为什么它给错误的值 ViewTreeObserver vto = horizontalLayout.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
ViewTreeObserver vto = horizontalLayout.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
horizontalLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
Log.i("WIDTH","Width "+horizontalLayout.getMeasuredWidth()+" width "+horizontalLayout.getWidth());
}
});
知道为什么会这样吗