使用 Scalpel 3D展示界面布局

来源:互联网 发布:db2数据库下载 编辑:程序博客网 时间:2024/04/29 12:29

无意中了解到iOS开发里面有一个叫Reveal的神器,用于UI调试。要是俺们安卓也能实现类似效果就好了。

Reveal看上去是这个样子的:

很酷炫有木有!

什么?Jake Wharton大神早在几年前就给我们准备了类似的开源库了!

今天要介绍的就是大神的Scalpel,可以实现在手机上3D展示届满布局,而且用起来超级简单!

在Gradle中引入Scalpel:

compile 'com.jakewharton.scalpel:scalpel:1.1.2'

然后我们来到需要展示效果的布局文件,将它的根布局修改为ScalpelFrameLayout,看名字也能猜到它是继承FrameLayout的。(要是去看源码你会发现,其实整个库只有ScalpelFrameLayout这一个文件,四百多行代码,膜拜大神!)

然后在代码里面将setContentView修改成以下代码:

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);

跑一下看看效果:

妥妥的。

你问我有什么用?酷炫啊!

0 0
原创粉丝点击