0

So I have a main_activity with DrawerLayout. This activity has FrameLayout which is inflated with the layout of fragment_forecast. Fragment_forecast has TabLayoutwhich holds three other fragments. All of this child fragment layouts overlap tabs of TabLayout.enter image description here

I tried to use LinearLayout instead of FrameLayout inside fragment_forecast but the result is that bottom part of child_fragments is cut off.

What is a proper way to handle this situation ?

Activity layout for main_activity:

    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.example.daza.soundmap.Main2Activity">

    <LinearLayout android:layout_width="match_parent"
        android:layout_height="match_parent"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:orientation="vertical"
        xmlns:android="http://schemas.android.com/apk/res/android">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="enterAlways"
            android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
            />

        <FrameLayout
            android:id="@+id/main_activity_frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    </LinearLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header"
        app:menu="@menu/drawer_view" />

</android.support.v4.widget.DrawerLayout>

Fragment layout for fragment_day_forecast (child of forecast_fragment) :

<FrameLayout 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"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context="com.example.daza.soundmap.ForecastFragment">


    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabBackground="@color/primaryLightColor"
        app:tabIndicatorColor="@color/secondaryColor"
        app:tabMode="fixed"
        app:tabSelectedTextColor="@color/primaryTextColor"
        app:tabTextColor="@color/primaryTextColor" />

    <android.support.v4.view.ViewPager
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
       />

</FrameLayout>

Fragment layout for fragment_day_forecast:

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/frameLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.daza.soundmap.DayForecastFragment"
   >

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe_refresh_layout_hour"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view_hour_forecast"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scrollbars="vertical" />
    </android.support.v4.widget.SwipeRefreshLayout>

</android.support.constraint.ConstraintLayout>
dawzaw
  • 419
  • 6
  • 17

2 Answers2

1

Try this bunch of code. Replace FragmentLayout with RelativeLayout and set viewpager below id tabs .

<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"
   xmlns:app="http://schemas.android.com/apk/res-auto">

<android.support.design.widget.TabLayout
    android:id="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:tabMode="fixed" />

<android.support.v4.view.ViewPager
    android:id="@+id/view_pager"
    android:layout_below="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    />

</RelativeLayout>
Payal Sorathiya
  • 756
  • 1
  • 8
  • 23
0

TabLayout is overlapping with ViewPager Fragment because Your parent of fragment_day_forecast is

  • FrameLayout
    • TabLayout
    • ViewPager

Where FrameLayout is meant to put one View over another.

You need to use RelativeLayout as a parent view. i.e., Set relation between views. In this case, It will be ViewPager below TabLayout. Something like(fragment_day_forecast),

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.daza.soundmap.ForecastFragment">

<android.support.design.widget.TabLayout
    android:id="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:tabBackground="@color/primaryLightColor"
    app:tabIndicatorColor="@color/secondaryColor"
    app:tabMode="fixed"
    app:tabSelectedTextColor="@color/primaryTextColor"
    app:tabTextColor="@color/primaryTextColor" />

<android.support.v4.view.ViewPager
    android:id="@+id/view_pager"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/tabs" />
</RelativeLayout>
buzzingsilently
  • 1,546
  • 3
  • 12
  • 18