使用 Scalpel 3D 展示界面布局

作者: NanBox | 来源:发表于2017-02-25 18:52 被阅读430次

    本篇文章已授权微信公众号code小生发布
    转载请注明出处:
    http://www.jianshu.com/p/8ea577c60865

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

    跑一下看看效果:

    妥妥的。

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

    相关文章

      网友评论

        本文标题:使用 Scalpel 3D 展示界面布局

        本文链接:https://www.haomeiwen.com/subject/vrdnwttx.html