无心中了解到 iOS 开发里面有一个叫 Reveal 的神器,用于 UI 调试。要是俺们安卓也能实现相似效果就行了。java
Reveal 看上去是这个样子的:bash
很酷炫有木有!布局
什么?Jake Wharton 大神早在几年前就给咱们准备了相似的开源库了!this
今天要介绍的就是大神的 Scalpel,能够实如今手机上 3D 展现届满布局,并且用起来超级简单!spa
在 Gradle 中引入 Scalpel:调试
compile 'com.jakewharton.scalpel:scalpel:1.1.2'
复制代码
而后咱们来到须要展现效果的布局文件,将它的根布局修改成 ScalpelFrameLayout,看名字也能猜到它是继承 FrameLayout 的。(要是去看源码你会发现,其实整个库只有 ScalpelFrameLayout 这一个文件,四百多行代码,膜拜大神!)code
而后在代码里面将 setContentView 修改为如下代码:cdn
View mainView = getLayoutInflater().inflate(R.layout.activity_main, null);
ScalpelFrameLayout mScalpelFrameLayout = new ScalpelFrameLayout(this);
mScalpelFrameLayout.addView(mainView);
mScalpelFrameLayout.setLayerInteractionEnabled(true); //开启 3D 效果
//mScalpelFrameLayout.setDrawIds(true); //是否显示控件 id
//mScalpelFrameLayout.setDrawViews(false); //是否展现控件内容,默认为 true
//mScalpelFrameLayout.setChromeColor(Color.RED); //修改边框颜色
//mScalpelFrameLayout.setChromeShadowColor(Color.YELLOW); //修改阴影颜色
setContentView(mScalpelFrameLayout);
复制代码
跑一下看看效果:blog
妥妥的。继承
你问我有什么用?酷炫啊!