The short question How do you impliment a SwipeRefreshLayout on an Activity that hosts two Fragments side by side in such a way that the refresh loading spinner apeares centered in the screen.
**The Long question I have an activity that hosts several fragments. I would like to impliment a SwipeRefreshLayout on the activity level to the effect that no matter which fragments are showing, the refresh is available.
I have 1 base activity and 3 fragments. The fragments are hidden and shown using a fragment manager according the the program state. In some cases, one fragment will cover the entire space of the activity. in other cases 2 fragments will sit side by side and collectively cover the entire space of the activity.
When I implement the SwipeRefreshLayout on the fragment level, the refresh functions correctly, however in the case where I have 2 fragments side by side, the spinner will be centered to the fragment rather than the activity.
When I Implement the SwipeRefreshLayout on the Activity Level, the Fragments absorb the gesture events and the SwipeRefreshLayout is unresponsive.
What I want to have happen is a downward swipe anywhere in the side by side fragments layout to bring the refresh loading spinner down in the center according to the activity rather than the fragment. For this to happen, either I need to find a way to implement the SwipeRefreshLayout on the activity level where it will pickup on motion events observed in the fragments or I will need to implement the SwipeRefreshLayout on the fragment level and find a way to center the Loading spinner.
If anyone knows how to do either case, I would greatly appreciate the help. This is the xml file for my activity
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.activity.BaseActivity">
<!-- Layout with my fragments -->
<LinearLayout
android:id="@+id/fragmentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<!--Frame Layout for Dashboard List fragment-->
<FrameLayout
android:id="@+id/baseDashLayout"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:visibility="gone">
<fragment
android:id="@+id/baseDashFragment"
class="com.example.activity.fragment.DashboardListFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
<View
android:id="@+id/seperatorLine"
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#000000" />
<android.support.v4.app.FragmentTabHost
android:id="@+id/tabContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!--Layout for Tabs widget-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TabWidget
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:id="@+id/tabContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/tabs"
android:orientation="vertical" />
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
<!-- Frame Layout for Tabbed page Fragment-->
<FrameLayout
android:id="@+id/baseTabLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true">
<fragment
android:id="@+id/baseTabFragment"
class="com.example.fragment.PageTabFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
<!-- Frame layout for setup connection fragment -->
<FrameLayout
android:id="@+id/baseSetConLayout"
android:layout_width="fill_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/baseSetConFragment"
class="com.example.activity.fragment.SetConnectionFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
</LinearLayout>
<!-- End Layout with my fragments -->
<!-- Start Swipe to refresh Layout -->
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/baseRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>