我们可以在初始化view之后,使用
view.post(new Runnable(){
public void run(){
view.getHeight();
view.getwidth();
}
});
就可以拿到宽和高了。
那么为什么这种方法可以拿到呢?我们来看一下源码
public boolean post(Runnable action) { final AttachInfo attachInfo = mAttachInfo; if (attachInfo != null) { return attachInfo.mHandler.post(action); } // Postpone the runnable until we know on which thread it needs to run. // Assume that the runnable will be successfully placed after attach. getRunQueue().post(action); return true; }可以看到,系统帮助我们调用了handler.post方法,将其放置到消息队列中.