美文网首页
Android layout分层!

Android layout分层!

作者: 牧区叔叔 | 来源:发表于2020-10-29 07:53 被阅读0次

个人觉得分层的好处就是能快速找资源,资源不拥堵。
废话不多说,先看图。

包分层大家都知道


image.png

我这里主要说下res资源文件下的layout分层


image.png

放心资源文件是可以找得到的!
配置app的build.gradle 在Android标签添加

sourceSets {
        main {
            res.srcDirs =
                    [
                            'src/main/res/layouts/activities',
                            'src/main/res/layouts/fragments',
                            'src/main/res/layouts/adapters',
                            'src/main/res/layouts/popuwindows',
                            'src/main/res/layouts',
                            'src/main/res'
                    ]
        }
    }
image.png

之后clean项目,或者锤下(有时候自动出来了,我还没搞清楚,不想去搞了,反正我是复制粘贴以上自定义的名字在res文件下直接创建包,命名一样就行)

千万注意!

拿fragments这个说下!,虽然fragments包名,但是包名下一定要有layout包,再把xml文件放在layout包下!


image.png

我在想既然layout能分包drawable也应该可以吧?
这样selector、图片文件、以及shape之类的咱么也可以分开了~

最后你要是没有密集恐惧症无所谓~

相关文章

网友评论

      本文标题:Android layout分层!

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