简体   繁体   English

Android主模板布局文件?

[英]Android master template layout file?

I have more than 5 activities xml files in layout folder 我在layout文件夹中有5个以上的活动xml files
- login_activity.xml login_activity.xml
- user_profile_activity.xml user_profile_activity.xml
- product_activity.xml product_activity.xml
- buy_activity.xml buy_activity.xml
- sell_activity.xml sell_activity.xml

All layouts share the same header and footer views 所有布局共享相同的 headerfooter视图
So I create header.xml and footer.xml then include them in each layout xml file 所以我创建了header.xmlfooter.xml然后将它们包含在每个布局xml文件中

My problem 我的问题
Now I need to update layout of ALL activities by adding new view in the middle 现在,我需要通过在中间添加新视图来更新所有活动的布局
Currently solution to loop create middle.xml then include them in each! 当前循环创建middle.xml解决方案,然后将它们包含在每个中!
As you can see, simple change added in multiple files! 如您所见,简单的更改已添加到多个文件中!

Any other solution like Master Template concept 其他任何解决方案,例如“ Master Template概念
By using it, We can make a shared master template and each layout inherit this master template, then define ONLY its layout? 通过使用它,我们可以制作一个共享的主模板,并且每个布局都继承该主模板,然后仅定义其布局?

So the final picture will be something like that 所以最终的画面将是这样的

Subviews 子视图
- header.xml header.xml
- footer.xml footer.xml
- middle.xml middle.xml

Template will include header / footer / middle + contain main empty div 模板将包含header / footer / middle +包含主空div
- master_template.xml master_template.xml

Layouts will inherit master_template.xml + add impl to main empty div 布局将继承master_template.xml +将impl添加到主空div
- login_activity.xml login_activity.xml
- user_profile_activity.xml user_profile_activity.xml
- product_activity.xml product_activity.xml
- buy_activity.xml buy_activity.xml
- sell_activity.xml sell_activity.xml

Use FrameLayout and inflate it dynamically however you want. 使用FrameLayout并根据需要动态地对其进行充气。

Checkout this one : https://developer.android.com/reference/android/widget/FrameLayout 检出此一个: https : //developer.android.com/reference/android/widget/FrameLayout

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

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