Android 与回收商协调布局+;按钮

Android 与回收商协调布局+;按钮,android,android-layout,android-coordinatorlayout,android-appbarlayout,Android,Android Layout,Android Coordinatorlayout,Android Appbarlayout,我有一个问题,我试图添加一个按钮和一个回收视图到一个线性布局,该线性布局包含在一个坐标布局中。我遇到的问题是,当我将滚动行为应用于线性布局时,按钮会与操作栏的功能相反地上下滚动。当我对recylcerview和按钮应用滚动行为时,recylcer视图的顶部隐藏在操作栏后面 以下是我的布局: <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/re

我有一个问题,我试图添加一个按钮和一个回收视图到一个线性布局,该线性布局包含在一个坐标布局中。我遇到的问题是,当我将滚动行为应用于线性布局时,按钮会与操作栏的功能相反地上下滚动。当我对recylcerview和按钮应用滚动行为时,recylcer视图的顶部隐藏在操作栏后面

以下是我的布局:

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/coordinator_layout"

    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"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minHeight="?attr/actionBarSize"
            app:layout_scrollFlags="scroll|enterAlways"
            android:theme="@style/Theme.AppCompat.NoActionBar"
            app:popupTheme="@style/Theme.AppCompat.NoActionBar">

            <android.support.v7.widget.SearchView
                android:id="@+id/recommender_search_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:theme="@style/Theme.AppCompat.NoActionBar"
                app:popupTheme="@style/Theme.AppCompat.NoActionBar"/>

            </android.support.v7.widget.Toolbar>

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/contacts_recycler_view"
            android:layout_height="0dp"
            android:layout_width="match_parent"
            android:layout_weight="1"
            android:background="@color/recommender_divider"/>

        <Button
            style="@style/GrapeFullscreenButtonPrimary"
            android:id="@+id/send_button"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:text="Send (0)"/>

    </LinearLayout>

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


我不小心弄乱了fitSystemWindow属性,还尝试了前面提到的多个场景中的滚动行为。我已经为这个问题争论了一段时间,如果有任何帮助,我将不胜感激

好的,您可以使用以下技术实现相同的效果:


改变

  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/contacts_recycler_view"
        android:layout_height="0dp"
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:background="@color/recommender_divider"/>

    <Button
        style="@style/GrapeFullscreenButtonPrimary"
        android:id="@+id/send_button"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:text="Send (0)"/>

</LinearLayout>'

'


'


注意


appbar\u滚动\u查看\u行为
RecyclerView
向下移动,作为其实现的一部分;这就是为什么您的
按钮
应该有一个坚实的背景,否则您将看到它下面的
回收视图的一部分。

谢谢您的帮助。这个解决方案不起作用,但它确实让我找到了正确的解决方案。使用边距时,它在顶部留下了一个空白,但是添加边距作为填充确实有效。我之前也尝试过类似的解决方案,但我将这两个视图添加到relativelayout中,而不是协调器布局中,这使得它无法工作。更新你们的答案,包括填充底部,我会接受你们的答案。
 <android.support.v7.widget.RecyclerView
        android:id="@+id/contacts_recycler_view"
        android:layout_height="0dp"
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:background="@color/recommender_divider"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:paddingBottom="[your button's height]"/>

    <Button
        style="@style/GrapeFullscreenButtonPrimary"
        android:id="@+id/send_button"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:layout_gravity="bottom"
        android:text="Send (0)"/>'