Android 1.6的TabHost一个片段内 [英] Android 1.6 TabHost inside a Fragment
问题描述
在演示 Support4Demos - API 4+支持演示中,标签和TabsPager例子都扩展FragmentActivity。每个选项卡的内容本身就是一个片段。没有真正的突破,TabActivity使用了同样的方式,而不采用片段。
In the demo Support4Demos - API 4+ Support Demos , the Tabs and TabsPager examples both extend FragmentActivity. Each tab content is itself a Fragment. No real breakthrough, TabActivity was used the same way without the introduction of Fragment.
现在假设我的活动里面,屏幕部分是名为WidgetFragment片段。这怎么可能WidgetFragment含有一个TabHost?可视化包含在活动内的迷你TabHost。 我试图插入内片段的TabHost不是FragmentActivity无微不至。
Now suppose inside my Activity , a screen portion is a Fragment named WidgetFragment. How is it possible for WidgetFragment to contain a TabHost ? Visualize a mini TabHost contained inside an Activity. I tried every possible way to insert a TabHost inside a Fragment not a FragmentActivity.
推荐答案
在普遍接受的做法,标签适应整个屏幕。 大多数人(包括我)不知道该标签可以放在任何地方像一个简单的观点,ListView控件。 关键是要包括你的TabHost在另一个布局。当您创建TabHost,始终保持这些ID: tabhost,标签,tabcontent
In generally accepted practices, Tabs fit the whole screen. Most people (including me) are unaware the tabs can be placed anywhere like a simple view, ListView. The trick is to include your TabHost inside another layout. When you create the TabHost, always keep these id : tabhost , tabs , tabcontent
在主布局,包括您的tabhost.xml。在这里,我中心TabHost中间
In your main layout, include your tabhost.xml . Here I center the TabHost in the middle
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<!-- Fill whatever you need -->
<FrameLayout
android:id="@+id/widget_fragment"
android:layout_centerVertical="true" android:layout_centerHorizontal="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<include layout="@layout/tabhost" />
</FrameLayout>
</LinearLayout>
在Support4Demos的标签和TabsPager例子看看好了,TabHost仍由FragmentActivity管理。每个选项卡的内容是一个片段。与TabActivity,它可能无法在任何地方有一个标签
Look well at the Tabs and TabsPager examples in Support4Demos , the TabHost is still managed by FragmentActivity. Each tab content is a fragment. With TabActivity, it may not be possible to have a tab anywhere
最后,该是什么样子
这篇关于Android 1.6的TabHost一个片段内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!