关于在Android中一个XML文件包含另外一个XML的方法
在Android界面設(shè)計中,有時候需要一個XML主界面需要包含很多的子界面,如果寫在同一個XML文件,該文件結(jié)構(gòu)過于復雜,難以維護,因此可以考慮把各個子界面寫成獨立的XML文件,然后包含到主界面xml文件中,方法如下:
1.直接在XML中包含,寫法:
<LinearLayout ………………?
????? <include layout="@layout/foot" />
</LinearLayout>
上面的foot是layout文件夾里面的foot.xml
2.使用程序代碼實現(xiàn)
?????? View view=getLayoutInflater().inflate(R.layout.root,null);
?????? LinearLayout layout=(LinearLayout)findViewById(R.id.linearLayout1);
???????layout.addView(view);
或者?最方便的是
?RelativeLayout syset_main=(RelativeLayout)act.findViewById(R.id.syset_main);
Inflater.inflate(R.layout.roomcreate, syset_main, true);
其中syset_main是父XML,roomcreate是需要添加的子XML
轉(zhuǎn)載于:https://www.cnblogs.com/chang-bin/p/android.html
總結(jié)
以上是生活随笔為你收集整理的关于在Android中一个XML文件包含另外一个XML的方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: NSArray和NSDictionary
- 下一篇: jQuery 标签切换----之选项卡的