片段内的 Android 1.6 TabHost [英] Android 1.6 TabHost inside a Fragment

查看:29
本文介绍了片段内的 Android 1.6 TabHost的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在演示 Support4Demos - API 4+ 支持演示中,Tabs 和 TabsPager 示例都扩展了 FragmentActivity.每个选项卡内容本身就是一个片段.没有真正的突破,TabActivity 的使用方式是一样的,没有引入 Fragment.

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.

现在假设在我的 Activity 中,屏幕部分是一个名为 WidgetFragment 的 Fragment.WidgetFragment 怎么可能包含 TabHost ?可视化包含在 Activity 中的迷你 TabHost.我尝试了所有可能的方法在 Fragment 而不是 FragmentActivity 中插入 TabHost.

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 , tabs , 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中的Tabs和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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆