使用 Scalpel 3D展示界面布局

介绍了JakeWharton的Scalpel库,可在安卓设备上实现3D展示界面布局的效果,使用简单且功能强大。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

无意中了解到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);

跑一下看看效果:

妥妥的。

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值