英文:
Can multiple fragments share a single XML layout
问题
我有多个共享相同布局的片段,其中包含一个放置在LinearLayout
内部的RecyclerView
。过去,我有如下文件:
fragment_one.xml
fragment_two.xml
fragment_three.xml
fragment_four.xml
不过,我目前在考虑是否更好地使用一个名为fragment_generic
的单一布局。这是一个好主意还是坏主意?
谢谢。
英文:
I have multiple fragments that share the same layout which is a RecyclerView
inside a LinearLayout
. In the past, I had files like:
fragment_one.xml
fragment_two.xml
fragment_three.xml
fragment_four.xml
Though, I am currently questioning if it is better, to use a single layout named, for example, fragment_generic
. Is this a good or bad idea?
Thanks.
答案1
得分: 3
这实际上取决于您的用途。如果您有大约5个片段,它们具有相同的布局,即单个RecyclerView列表。最好为所有目的使用单个布局。这会使应用程序变得非常紧凑。
稍后,当出现一些更改并且您想要添加项目,比如说一个浮动操作按钮图标,那么创建一个新的布局,并仅将其用于已更改的片段。
所以关于您的问题,是的,为这4个片段使用相同的布局将是最佳选择。
英文:
It actually depends on your use case. If you have like 5 fragments which have the same layout i.e a single recyclerview list. It is better to use a single layout for all the purposes. That makes the application really compact.
Later, when some changes come into place and you want to add item , let's suppose a fab icon, then create a new layout and use it for the changed fragment only.
So about your question, yes it would be the best idea to use the same layout for these 4 fragments.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论