在没有appbar_scrolling_view_behavior

时间:2016-12-14 17:59:28

标签: android android-layout android-coordinatorlayout

我正在使用一个包含AppBarLayout和FrameLayout的CoordinatorLayout,它将在运行时保存不同的片段。我需要使用appbar_scrolling_view_behavior属性将FrameLayout始终低于AppBarLayout 而不使用。出于某种原因(即尝试使用RecyclerView和浮动页脚按钮来处理片段),我在片段中的RecylerView上应用此属性。滚动工作正常,但FrameLayout认为它应该具有屏幕的完整高度。这通常由appbar_scrolling_view_behavior修复,但我不能在此处使用它。我试过layout_anchor和layout_anchorGravity几乎没有效果。

有什么想法吗?

布局:

<?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"
                                                 android:layout_width="match_parent"
                                                 android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            style="@style/AppTheme.Toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_scrollFlags="scroll|enterAlways"
            />

        <android.support.design.widget.TabLayout
            android:id="@+id/tab_layout"
            style="@style/NavigationTab"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            />
    </android.support.design.widget.AppBarLayout>

    <!-- Fragments go here; they will set appbar_scrolling_view_behavior themselves -->
    <!-- layout_anchor and layout_anchorGravity don't work -->
    <FrameLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_anchor="@id/app_bar_layout"
        app:layout_anchorGravity="bottom|left|right"/>

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

其中一个片段的布局:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:orientation="vertical"
             android:paddingEnd="15dp"
             android:paddingStart="15dp">

    <!-- Bottom padding is so the last row isn't fully covered by the button -->
    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        android:paddingBottom="55dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

    <Button
        android:id="@+id/add_photo_button"
        style="@style/ProductActionButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal|bottom"
        android:layout_marginBottom="15dp"
        android:drawableStart="@drawable/white_camera"
        android:text="@string/product_photo_add"/>
</FrameLayout>

0 个答案:

没有答案