在Android的Support4Demos的FragmentTabs例如两个框架布局 [英] Two frame layouts in FragmentTabs example of Android Support4Demos

查看:171
本文介绍了在Android的Support4Demos的FragmentTabs例如两个框架布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的Andr​​oid的碎片,我指片段演示实例提供supprotv4兼容库。

I am new to fragments in Android and I am referring Fragments demo examples provide for supprotv4 compatibility library.

任何人都可以解释为什么有两个框架布局(@ +安卓:ID / realtabcontent,@android:ID / tabcontent)从Android的Support4Demos FragmentTabs.java例子。

Can anyone explain why there are two frame layouts (@+android:id/realtabcontent , @android:id/tabcontent) in FragmentTabs.java example from Android Support4Demos.

FragmentTabs.java通话的setContentView(R.layout.fragment_tabs); 方法和下面是相同的布局文件

FragmentTabs.java call setContentView(R.layout.fragment_tabs); method and following is the layout file for the same.

fragment_tabs.xml

    <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>

在此先感谢

推荐答案

通过实例去后,我发现在 FragmentsTabs.java

After going through the example I found following comment in FragmentsTabs.java

 /**
 * 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.
 */

这篇关于在Android的Support4Demos的FragmentTabs例如两个框架布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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