
>活动中的Java代码
>为每个选项卡分开活动
>为每个标签分隔碎片
标签内的内容是静态的,所以我应该能够将所有内容都包含在纯XML中.
反正这样做
解决方法 简单的答案,不.您必须在Java代码中设置您的TabHost并创建您的选项卡.您可以在不使用片段的情况下为选项卡提供静态布局,但仍需要使用Java进行安装.如果您不在代码中执行此设置,您的TabWidget将不知道哪个布局对应于哪个选项卡,将无法正常工作.你将不得不写一点代码.
这样做的代码真的很简单.
XML(放置在你想要的布局中):
<TabHost androID:ID="@+ID/tab_host" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" > <linearLayout androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:orIEntation="vertical"> <TabWidget androID:ID="@androID:ID/tabs" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" /> <FrameLayout androID:ID="@androID:ID/tabcontent" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content"> <linearLayout androID:ID="@+ID/tab_one_container" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" /> <linearLayout androID:ID="@+ID/tab_two_container" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" /> </FrameLayout> </linearLayout></TabHost>
Java代码(放置在您设置布局的地方):
TabHost host = (TabHost)findVIEwByID(R.ID.tab_host);host.setup();TabSpec spec = host.newTabSpec("Tab One");spec.setContent(R.ID.tab_one_container);spec.setIndicator("Tab One");host.addTab(spec);spec = host.newTabSpec("Tab Two");spec.setContent(R.ID.tab_two_container);spec.setIndicator("Tab Two");host.addTab(spec); 总结 以上是内存溢出为你收集整理的android – 如何使用XML完整的标签创建布局?全部内容,希望文章能够帮你解决android – 如何使用XML完整的标签创建布局?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)