0

我有一个问题,我试图将一个按钮和一个 recyclerview 添加到一个线性布局,该线性布局包含在一个 coordinatorlayout 中。我遇到的问题是,当我将滚动行为应用于 linearLayout 时,按钮会向上和向下滚动,与操作栏的作用相反。半操作栏半按钮当我将滚动行为应用到 recyclerview 和按钮时,我的 recycler 视图的顶部隐藏在操作栏后面。

这是我的布局的样子:

<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 属性,但没有运气,并且还尝试了前面提到的多种场景的滚动行为。我一直在与这个问题作斗争一段时间,任何帮助将不胜感激。

4

1 回答 1

2

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


改变

  <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.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)"/>'



注意

appbar_scrolling_view_behaviorRecyclerView向下移动作为其实施的一部分;这就是为什么你Button应该有一个坚实的背景,否则你会看到RecyclerView它下面的一部分。

于 2015-11-06T15:15:34.730 回答