简体   繁体   中英

Android master template layout file?

I have more than 5 activities xml files in layout folder
- login_activity.xml
- user_profile_activity.xml
- product_activity.xml
- buy_activity.xml
- sell_activity.xml

All layouts share the same header and footer views
So I create header.xml and footer.xml then include them in each layout xml file

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!
As you can see, simple change added in multiple files!

Any other solution like Master Template concept
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
- footer.xml
- middle.xml

Template will include header / footer / middle + contain main empty div
- master_template.xml

Layouts will inherit master_template.xml + add impl to main empty div
- login_activity.xml
- user_profile_activity.xml
- product_activity.xml
- buy_activity.xml
- sell_activity.xml

Use FrameLayout and inflate it dynamically however you want.

Checkout this one : https://developer.android.com/reference/android/widget/FrameLayout

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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