Two-frame layouts in the FragmentTabs Android Support4Demos example

I'm new to snippets on Android, and I mean the examples of the Fragments demos for the supprotv4 compatibility library.

Can someone explain why there are two layout frames (@+android:id/realtabcontent , @android:id/tabcontent) in the FragmentTabs.java example from Android Support4Demos.

FragmentTabs.java method call setContentView(R.layout.fragment_tabs); and the next is a 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> 

Thank you in advance

+4
source share
1 answer

After going through the example, I found the 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. */ 
+4
source

Source: https://habr.com/ru/post/1432945/


All Articles