首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android Support4Demos的FragmentTabs示例中的两个框架布局

Android Support4Demos的FragmentTabs示例中的两个框架布局
EN

Stack Overflow用户
提问于 2012-09-07 21:10:28
回答 1查看 2.3K关注 0票数 4

我对Android中的片段是新手,我指的是为supprotv4兼容性库提供的片段演示示例。

谁能解释一下为什么在Android Support4Demos的FragmentTabs.java例子中有两个框架布局(@+android:id/realtabcontent , @android:id/tabcontent)

FragmentTabs.java调用setContentView(R.layout.fragment_tabs);方法,下面是该方法的布局文件。

fragment_tabs.xml

代码语言:javascript
复制
    <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@android:id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0"
                android:orientation="horizontal" />

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_weight="0" />

            <FrameLayout
                android:id="@+android:id/realtabcontent"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1" />
        </LinearLayout>

    </TabHost>

提前感谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-09-09 02:35:26

浏览完示例后,我在FragmentsTabs.java中找到了以下注释

代码语言:javascript
复制
 /**
 * This is a helper class that implements a generic mechanism for
 * associating fragments with the tabs in a tab host. It relies on a trick.
 * Normally a tab host has a simple API for supplying a View or Intent that
 * each tab will show. This is not sufficient for switching between
 * fragments. So instead we make the content part of the tab host 0dp high
 * (it is not shown) and the TabManager supplies its own dummy view to show
 * as the tab content. It listens to changes in tabs, and takes care of
 * switch to the correct fragment shown in a separate content area whenever
 * the selected tab changes.
 */
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12318808

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档