5

I have an activity layout that looks like the following:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        app:layout_scrollFlags="scroll|enterAlways"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary" />

    <android.support.design.widget.TabLayout
        android:id="@+id/tab_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>

<android.support.v4.view.ViewPager
    android:id="@+id/view_pager"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

The viewpager has two fragments, one with a RecyclerView and one with a LinearLayout.

The fragment with RecyclerView works as expected and the action bar scrolls off screen when the RecyclerView is scrolled.

The other fragment with the LinearLayout isn't displaying as I would like it to however. The LinearLayout is drawn below the TabLayout and extends offscreen. I would like it to be resize to fill the space available below the TabLayout without extending offscreen. The LinearLayout looks like this:

    <LinearLayout 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"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/station_detail_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <include
            layout="@layout/station_detail_title"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="3" />

        <include
            layout="@layout/station_detail_body"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="2" />


    </LinearLayout>

    <TextView
        android:id="@+id/text_view_station_detail_empty"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center_horizontal|center_vertical"
        android:text="@string/text_view_station_detail_empty"
        android:visibility="gone" />
</LinearLayout>

Thanks for any help, much appreciated!

Alex Holliday
  • 123
  • 1
  • 13
  • 1
    Did you solve this? I have the same problem. Thanks! – Marta Rodriguez Nov 10 '15 at 12:22
  • 1
    I never really found a satisfactory solution to this problem. What I ended up doing was adding a margin to the bottom of my LinearLayout that was equal to the height of the appbar. This keeps everything on screen, but if the appbar has been collapsed from scrolling one of the other fragments the margin will be visible as blank space. – Alex Holliday Dec 01 '15 at 09:53

2 Answers2

1

I think you need to add nested scroll view to your linearlayout.

Anil Kumar
  • 31
  • 1
  • 4
0

Alex I thing you have to use two CoordinatorLayout in two fragment and you can include your linear layout inside it .