I have a fragment with a name HostFragmentthat contains from one to four other fragments.
This is the layout HostFragment:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/hostFragmentLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="12dp">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<RelativeLayout
android:id="@+id/fragmentContainer1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"/>
<RelativeLayout
android:id="@+id/fragmentContainer2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<RelativeLayout
android:id="@+id/fragmentContainer3"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"/>
<RelativeLayout
android:id="@+id/fragmentContainer4"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"/>
</TableRow>
</TableLayout>
An important part of this is android:layout_marginTop="12dp".
Background: Nested fragments cover everything HostFragmentexcept this field. When nested fragments change their background color (causing Canvas#drawColor), HostFragmentyou must also change the color of this field to match. I keep the necessary color in SharedPreferences.
: HostFragment SettingsActivity, HostFragment, ( onResume()), HostFragment - . HostFragment , HostFragment, . , - HostFragment, . HostFragment .
: , onResume() - mTableLayout.setBackgroundColor(...) mView.setBackgroundColor(...) (mView - onCreateView()). , , .
: , int SharedPreferences, HostFragment Activity (.. )?
!