[英]coordinator layout with recycler + button
我在嘗試向linearLayout中包含一個線性布局包含在coordinatorlayout中的linearLayout中添加一個按鈕和一個recyclerview時遇到問題。 我遇到的問題是,當我將滾動行為應用於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
一部分。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.