我对 Android 中的片段不熟悉,我指的是为 supportv4 兼容性库提供的片段演示示例。
谁能解释一下为什么有两种框架布局(@+android:id/realtabcontent , @android:id/tabcontent)
Android Support4Demos 中的 FragmentTabs.java 示例。
FragmentTabs.java 调用setContentView(R.layout.fragment_tabs);
方法和以下是相同的布局文件。
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
/**
* 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.
*/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)