1

我正在尝试使用 CoordinatorLayout、Viewpager 创建一个活动,并在其中创建一个带有 FAB 的普通视图。我要创建的布局是:

- CoordinatorLayout
    - ViewPager
        - View with FAB
        - View
        - etc

所以在我的情况下,我需要在 ViewPager 的视图中包含 FAB。我现在的问题是(在简化的应用程序中): https : //gfycat.com/VacantAdmiredBedlingtonterrier GIF 中的问题是 FAB 移出屏幕。它精确地移动工具栏的高度。

我想要的是 FAB 将保持在其位置,但在 viewpager 和视图中。

此视图的 XML 为:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/app_bar_height"
    android:fitsSystemWindows="true"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/toolbar_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

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

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

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|center_horizontal"/>

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/text_margin"
            android:text="@string/large_text" />

    </android.support.v4.widget.NestedScrollView>
</FrameLayout>

如 XML 所示,FAB 不在滚动视图中,而是在 FrameLayout 内部,这将代表一个 ViewPager。

有什么方法可以让这个 FAB 保持在它的位置,但将视图保持在一个 viewpager 内?

4

0 回答 0