带有回收器+按钮的协调器布局
coordinator layout with recycler + button
我遇到了一个问题,我试图将一个按钮和一个回收视图添加到线性布局中,线性布局包含在一个协调器布局中。我遇到的问题是,当我将滚动行为应用于 linearLayout 时,按钮会向上和向下滚动,这与操作栏的作用相反。 当我将滚动行为应用于 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>'
到
<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_behavior
会将 RecyclerView
作为其实施的一部分下移;这就是为什么您的 Button
应该具有纯色背景,否则您会在其下方看到 RecyclerView
的一部分。
我遇到了一个问题,我试图将一个按钮和一个回收视图添加到线性布局中,线性布局包含在一个协调器布局中。我遇到的问题是,当我将滚动行为应用于 linearLayout 时,按钮会向上和向下滚动,这与操作栏的作用相反。
这是我的布局:
<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>'
到
<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_behavior
会将 RecyclerView
作为其实施的一部分下移;这就是为什么您的 Button
应该具有纯色背景,否则您会在其下方看到 RecyclerView
的一部分。