0

我有一個問題,我想添加一個按鈕和一個recyclerview線性佈局包含在協調器佈局中的linearLayout。我遇到的問題是,當我將滾動行爲應用於linearLayout時,該按鈕然後在操作欄的相反位置上下滾動。 Half Actionbar Half Button當我將滾動行爲應用於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財產周圍亂七八糟,也試圖與多個場景滾動行爲如前所述。我一直在解決這個問題一段時間,任何幫助將不勝感激。

回答

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



Note

appbar_scrolling_view_behavior將作爲其實施的一部分向下移動RecyclerView;這就是爲什麼你的Button應該有一個堅實的背景,或者你會看到它下面的一部分RecyclerView

+0

感謝您的幫助。這個解決方案不起作用,但它確實使我找到了正確的解決方案。使用Margin它在頂部留下了一個空白空間,但是將其作爲填充添加時確實可以正常工作。我早些時候嘗試過類似的解決方案,但是我將2個視圖添加到了一個相關佈局中,而不是在協調器佈局中使其無法工作。更新你的答案,包括填充底部,我會接受你的答案。 – ocross

+0

感謝您糾正我。 – Ari