如何将带有片段的协调器布局用作“滚动视图"? [英] How to use coordinator layout with fragment as "scrolling view"

查看:74
本文介绍了如何将带有片段的协调器布局用作“滚动视图"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将协调器布局与将片段作为滚动视图"托管的appbar布局一起使用.该片段包括一个recyclerView和一个底部对齐的布局,其中包含一个按钮,如下所示:

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.

在我的活动课堂上:

    @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();
}

活动布局:

<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>

片段布局:

<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.

这可能吗?

谢谢!

推荐答案

目前看来这不可能(永远吗?).

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

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

这篇关于如何将带有片段的协调器布局用作“滚动视图"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆