1.真机使用需要导入如下(参考https://github.com/romainguy/ViewServer)
build.gradle里加入:
allprojects {
repositories {
//需要加入下面两行
jcenter()
maven { url "https://jitpack.io" }
}
}
然后在dependence里加依赖:
compile 'com.github.romainguy:ViewServer:017c01cd512cac3ec054d9eee05fc48c5a9d2de'
2.在你需要进行布局优化的activity里进行如下操作:
onCreate加入:
ViewServer.get(this).addWindow(this);
onResume加入:
ViewServer.get(this).setFocusedWindow(this);
onDestroy加入:
ViewServer.get(this).removeWindow(this);
3.点工具栏的tool->Android->Android Device Monitor->window->open perspective->Hierarchy Viewer即可
付自己的图: