简体   繁体   English

AndroidStudio - 活动和布局问题

[英]AndroidStudio - Activities and Layouts question

Should I use a lot of layouts for a few activities or should I have a lot of activities with one or two layouts for each.我应该为一些活动使用很多布局,还是应该有很多活动,每个活动都有一个或两个布局。 I noticed that using a bunch of layouts for the same activity makes the activity code very messy compared to having one or two layouts for each activity, but for some reason I have the impression that having a lot of layouts instead of activities makes the app faster.我注意到,与为每个活动使用一个或两个布局相比,为同一个活动使用一堆布局会使活动代码非常混乱,但出于某种原因,我的印象是拥有大量布局而不是活动会使应用程序更快.

It depends on your use case if for example you have a recyclerview or a list in your activity, I think its generally safe to say you will have multiple layouts definitely for separation of concern.这取决于您的用例,例如,如果您的活动中有一个 recyclerview 或一个列表,我认为通常可以肯定地说您肯定会有多个布局来分离关注点。 Although nowadays, I think a single activity is recommended, layouts are managed through fragments and navigation component.虽然现在,我认为建议使用单个活动,但布局是通过片段和导航组件管理的。 If you only have simple use case, I think its fair enough to reuse as much layout as possible especially if the other activity looks much like the other (Just modify the content in the class).如果您只有简单的用例,我认为它可以公平地重用尽可能多的布局,特别是如果其他活动看起来很像其他活动(只需修改类中的内容)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM