android getwidth 为0的时候,是因为空间还没有draw,所以拿到宽度和高度为0,需要等到控件绘制完成才可以取得,所以我们可以将取高宽度的代码,放在单独的线程里面延迟处理一下,如下代码:
//延迟操作,取得webview的高宽值
handler.postDelayed(new Runnable() {
@Override
public void run() {
// 首次登陆,设置悬浮组建的范围,并保存下来,给缩小的时候设置范围
webviewWidth = first_chart_webview.getWidth();
webviewHeight = first_chart_webview.getHeight();
DocCaptain.getInstance().setWebviewWidth(webviewWidth);
DocCaptain.getInstance().setWebviewHeight(webviewHeight);
}
}, 5000);