How to use coordinator layout with fragment as “scrolling view”

余生长醉 提交于 2019-12-22 04:22:12

问题


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:

However, the bottom section is hidden by default:

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!


回答1:


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

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



来源:https://stackoverflow.com/questions/31709100/how-to-use-coordinator-layout-with-fragment-as-scrolling-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!