Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use coordinator layout with fragment as "scrolling view"

I'm trying to use a coordinator layout with an appbar layout that hosts a fragment as the "scrolling view". The fragment consists of a recyclerView and a bottom aligned layout holding a button, like so:

enter image description here

However, the bottom section is hidden by default:

enter image description here

and only shows up after I scroll.

From my activity class:

    @Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    TestFragment fragment = (TestFragment) getFragmentManager().findFragmentByTag("Test");
    if (fragment == null)
        fragment = new TestFragment();

    getFragmentManager().popBackStack();

    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();

    fragmentTransaction.replace(R.id.fragment_container, fragment, "Test");
    fragmentTransaction.commit();
}

Activity layout:

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

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/main_content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

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

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

            <android.support.design.widget.TabLayout
                android:id="@+id/tabs"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_scrollFlags="enterAlways|scroll"
                app:tabGravity="fill"
                app:tabMode="fixed"/>

        </android.support.design.widget.AppBarLayout>

    </android.support.design.widget.CoordinatorLayout>

</RelativeLayout>

Fragment layout:

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

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/bottomView"
        android:scrollbars="vertical"
        android:visibility="visible"/>

    <RelativeLayout
        android:id="@+id/bottomView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="#d4285d"
        app:layout_scrollFlags="enterAlways">

        <Button
            android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Do something..."
            android:textSize="14sp"/>

    </RelativeLayout>
</RelativeLayout>

The end goal here is for the fragment to have the bottom bar always on screen, and the recycler view scrolling the appbar away.

Is this possible?

Thanks all!

like image 585
Zach Avatar asked Jul 29 '15 19:07

Zach


1 Answers

It seems this is impossible to do at the moment (forever?).

https://code.google.com/p/android/issues/detail?id=177195

like image 89
Zach Avatar answered Nov 04 '22 00:11

Zach