Android 在recyclerview内部coordinatorlayout上实现自定义行为

Android 在recyclerview内部coordinatorlayout上实现自定义行为,android,android-recyclerview,android-coordinatorlayout,android-appbarlayout,Android,Android Recyclerview,Android Coordinatorlayout,Android Appbarlayout,我的布局文件中有3个视图,CoordinatorLayout作为根视图:AppbarLayout、RecyclerView和一个页脚(始终不可见)。Recyclerview实现默认行为appbar\u滚动\u查看\u行为,理想情况下,将Recyclerview置于appbarlayout之下。但recyclerview和页脚重叠。为了防止这种情况发生,我必须编写一个自定义行为,这样当页脚可见时,Recyclerview应该为页脚留出空间。但是现在,appbar_滚动_查看_行为的默认行为消失了,

我的布局文件中有3个视图,CoordinatorLayout作为根视图:AppbarLayout、RecyclerView和一个页脚(始终不可见)。Recyclerview实现默认行为appbar\u滚动\u查看\u行为,理想情况下,将Recyclerview置于appbarlayout之下。但recyclerview和页脚重叠。为了防止这种情况发生,我必须编写一个自定义行为,这样当页脚可见时,Recyclerview应该为页脚留出空间。但是现在,appbar_滚动_查看_行为的默认行为消失了,现在appbarlayout和recyclerview重叠了

链接到我实现的自定义行为:

我的问题:如何实现两件事(在一个行为中同时实现):

  • 在协调器布局内的appbarlayout下方获取recyclerview
  • 如果页脚可见,则获取recycelerview为页脚留出空间
  • 如果你能提出一些解决办法,那也太好了!非常感谢

    
    //页脚子视图
    
    不要将android.support.design.widget.Coordinator布局保留为根布局

    将RelativeLayout添加为根布局。然后使用属性layout_alignParentTop和layout_over=“@+id/footerBar”添加android.support.design.widget.CoordinatorLayout,并将prokure.it.prokure.FooterBarLayout设置为align parent bottom作为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.design.widget.CoordinatorLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_above="@+id/footerBar">
    
            <android.support.design.widget.AppBarLayout
                android:id="@+id/appBarLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
    
                <android.support.v7.widget.Toolbar
                    android:id="@+id/app_bar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:background="?attr/colorPrimary"
                    app:layout_scrollFlags="scroll|enterAlways|snap" />
    
            </android.support.design.widget.AppBarLayout>
    
            <android.support.v7.widget.RecyclerView 
                android:id="@+id/list_recycler_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginTop="4dp"
                android:scrollbars="vertical"
                 />
        </android.support.design.widget.CoordinatorLayout>
    
        <prokure.it.prokure.FooterBarLayout
            android:id="@+id/footerBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom">
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
    
                //footer child views    
    
            </LinearLayout>
        </prokure.it.prokure.FooterBarLayout>
    </RelativeLayout>
    
    
    //页脚子视图
    
    不要将android.support.design.widget.Coordinator布局保留为根布局

    将RelativeLayout添加为根布局。然后使用属性layout_alignParentTop和layout_over=“@+id/footerBar”添加android.support.design.widget.CoordinatorLayout,并将prokure.it.prokure.FooterBarLayout设置为align parent bottom作为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.design.widget.CoordinatorLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_above="@+id/footerBar">
    
            <android.support.design.widget.AppBarLayout
                android:id="@+id/appBarLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
    
                <android.support.v7.widget.Toolbar
                    android:id="@+id/app_bar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:background="?attr/colorPrimary"
                    app:layout_scrollFlags="scroll|enterAlways|snap" />
    
            </android.support.design.widget.AppBarLayout>
    
            <android.support.v7.widget.RecyclerView 
                android:id="@+id/list_recycler_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginTop="4dp"
                android:scrollbars="vertical"
                 />
        </android.support.design.widget.CoordinatorLayout>
    
        <prokure.it.prokure.FooterBarLayout
            android:id="@+id/footerBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom">
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
    
                //footer child views    
    
            </LinearLayout>
        </prokure.it.prokure.FooterBarLayout>
    </RelativeLayout>
    
    
    //页脚子视图
    
    另一种更简单的方法是在prokure.it.prokure.FooterBarLayout中添加以下行

        app:layout_anchor="@id/list_recycler_view"
        app:layout_anchorGravity="bottom"
    
    并将prokure.it.prokure.FooterBarLayout保留在协调器布局中


    确保在“回收器”视图的末尾添加一个空单元格,以便prokure.it.prokure.FooterBarLayout不会与RecyclerView的最后一个单元格重叠。

    另一个更简单的方法是在prokure.it.prokure.FooterBarLayout中添加以下行

        app:layout_anchor="@id/list_recycler_view"
        app:layout_anchorGravity="bottom"
    
    并将prokure.it.prokure.FooterBarLayout保留在协调器布局中

    确保在recycler视图的末尾添加一个空单元格,以便prokure.it.prokure.FooterBarLayout不会与RecyclerView的最后一个单元格重叠