android - 如何使用 fragment 为 "scrolling view"的协调器布局

标签 android android-fragments appbar android-coordinatorlayout coordinator-layout

我正在尝试将协调器布局与应用栏布局一起使用,该布局将 fragment 托管为“ ScrollView ”。该 fragment 由一个 recyclerView 和一个底部对齐的布局组成,其中包含一个按钮,如下所示:

enter image description here

但是,底部部分默认隐藏:

enter image description here

并且仅在我滚动后显示。

来 self 的 Activity 课:

    @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 布局:

<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 布局:

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

这里的最终目标是让 fragment 的底部栏始终在屏幕上,并且回收器 View 将应用栏滚动开。

这可能吗?

谢谢大家!

最佳答案

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

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

关于android - 如何使用 fragment 为 "scrolling view"的协调器布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31709100/

相关文章:

flutter - 打开 SnackBar 内部函数发送到 AppBar

android - 使用两个 Viewholder 在 RecyclerView 中查看重叠

java - 具有相同 Fragment 的 Android 选项卡

android - 更改 fragment 中选项菜单的位置

android - 在 Fragment 类中显示 ProgressDialog

navigation-drawer - 如何在 Flutter 应用程序中同时显示抽屉按钮和后退按钮?

javascript - 如何使 material-ui-next 中的 AppBar 组件对滚动事件使用react

android - 从 FragmentTabHost 获取对嵌套 fragment 的引用

android - 如何创建 Recycler View Grid 分页?

android - 使用 firebase 函数问题的 cordova fcm 推送通知