0

我遇到CoordinatorLayout和RecyclerView這個奇怪的問題。CollapsingToolbarLayout在Recyclerview下方留下空白空間

正如你可以在圖片中看到,該RecyclerView離開它下面的空空白與完全相同的高度作爲申報CollapsingToolbarLayout的屬性了minHeight。

如果我沒有聲明這個屬性,LinearLayout將不會保持固定在屏幕的頂部(這就是所需的行爲)。

我我錯過了什麼?這是佈局的代碼和一些截圖。

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
 
    xmlns:tools="http://schemas.android.com/tools" 
 
    android:layout_width="match_parent" 
 
    android:layout_height="match_parent"> 
 

 
    <android.support.design.widget.AppBarLayout 
 
     android:id="@+id/appbar_profile" 
 
     android:layout_width="match_parent" 
 
     android:layout_height="@dimen/profile_header_height" 
 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 
 

 
     <android.support.design.widget.CollapsingToolbarLayout 
 
      android:id="@+id/collapsing_header" 
 
      android:layout_width="match_parent" 
 
      android:layout_height="match_parent" 
 
      android:minHeight="?attr/actionBarSize" 
 
      app:layout_scrollFlags="scroll|exitUntilCollapsed"> 
 

 
      <LinearLayout 
 
       android:layout_width="match_parent" 
 
       android:layout_height="wrap_content" 
 
       android:layout_centerInParent="true" 
 
       android:background="@drawable/bg_welcome" 
 
       android:orientation="vertical" 
 
       app:layout_collapseMode="parallax"> 
 

 
       <com.tourwhiz.pro.widgets.TextViewComfortaaBold 
 
        android:id="@+id/text_username" 
 
        style="@style/TextViewTW.Title" 
 
        android:layout_width="match_parent" 
 
        android:layout_height="wrap_content" 
 
        android:layout_margin="@dimen/view_size_normal" 
 
        android:gravity="center" 
 
        android:text="Juancho" 
 
        android:textSize="@dimen/text_size_medium" /> 
 

 
       <LinearLayout 
 
        android:id="@+id/linear_settings" 
 
        android:layout_width="match_parent" 
 
        android:layout_height="wrap_content" 
 
        android:gravity="center"> 
 

 
        <ImageView 
 
         android:id="@+id/image_settings" 
 
         android:layout_width="wrap_content" 
 
         android:layout_height="wrap_content" 
 
         android:src="@drawable/ic_settings_white" /> 
 

 
        <de.hdodenhof.circleimageview.CircleImageView 
 
         android:id="@+id/image_user" 
 
         android:layout_width="@dimen/profile_image_radious" 
 
         android:layout_height="@dimen/profile_image_radious" 
 
         android:layout_margin="@dimen/view_size_normal" 
 
         android:src="@drawable/madrid_01" 
 
         app:civ_border_color="@color/karma_aqua_blue" 
 
         app:civ_border_width="@dimen/view_size_tiny" /> 
 

 
        <ImageView 
 
         android:id="@+id/image_edit" 
 
         android:layout_width="wrap_content" 
 
         android:layout_height="wrap_content" 
 
         android:src="@drawable/ic_mode_edit_white" /> 
 
       </LinearLayout> 
 
      </LinearLayout> 
 

 
      <LinearLayout 
 
       android:id="@+id/linear_navigation" 
 
       android:layout_width="match_parent" 
 
       android:layout_height="wrap_content" 
 
       android:layout_gravity="bottom" 
 
       app:layout_collapseMode="pin" 
 
       android:background="@color/white" 
 
       android:orientation="horizontal"> 
 

 
       <LinearLayout 
 
        android:id="@+id/linear_posts" 
 
        android:layout_width="0dp" 
 
        android:layout_height="wrap_content" 
 
        android:layout_weight="1" 
 
        android:gravity="center" 
 
        android:orientation="vertical" 
 
        android:padding="@dimen/view_size_normal"> 
 

 
        <com.tourwhiz.pro.widgets.TextViewLatoRegular 
 
         style="@style/TextViewTW" 
 
         android:layout_width="match_parent" 
 
         android:layout_height="wrap_content" 
 
         android:gravity="center" 
 
         android:text="@string/profile_posts_text" 
 
         android:textSize="@dimen/text_size_large" /> 
 

 
        <com.tourwhiz.pro.widgets.TextViewLatoRegular 
 
         android:id="@+id/text_posts_count" 
 
         style="@style/TextViewTW" 
 
         android:layout_width="match_parent" 
 
         android:layout_height="wrap_content" 
 
         android:gravity="center" 
 
         android:textSize="@dimen/text_size_large" 
 
         tools:text="1456" /> 
 

 
       </LinearLayout> 
 

 
       <View 
 
        android:layout_width="@dimen/separator_height" 
 
        android:layout_height="match_parent" 
 
        android:layout_marginBottom="@dimen/text_size_normal" 
 
        android:layout_marginTop="@dimen/text_size_normal" 
 
        android:background="@color/dark_grey" /> 
 

 
       <LinearLayout 
 
        android:id="@+id/linear_friends" 
 
        android:layout_width="0dp" 
 
        android:layout_height="wrap_content" 
 
        android:layout_weight="1" 
 
        android:gravity="center" 
 
        android:orientation="vertical" 
 
        android:padding="@dimen/view_size_normal"> 
 

 
        <com.tourwhiz.pro.widgets.TextViewLatoRegular 
 
         style="@style/TextViewTW" 
 
         android:layout_width="match_parent" 
 
         android:layout_height="wrap_content" 
 
         android:gravity="center" 
 
         android:text="@string/profile_friends_text" 
 
         android:textSize="@dimen/text_size_large" /> 
 

 
        <com.tourwhiz.pro.widgets.TextViewLatoRegular 
 
         android:id="@+id/text_friends_count" 
 
         style="@style/TextViewTW" 
 
         android:layout_width="match_parent" 
 
         android:layout_height="wrap_content" 
 
         android:gravity="center" 
 
         android:textSize="@dimen/text_size_large" 
 
         tools:text="1" /> 
 

 
       </LinearLayout> 
 

 
       <View 
 
        android:layout_width="@dimen/separator_height" 
 
        android:layout_height="match_parent" 
 
        android:layout_marginBottom="@dimen/text_size_normal" 
 
        android:layout_marginTop="@dimen/text_size_normal" 
 
        android:background="@color/dark_grey" /> 
 

 
       <LinearLayout 
 
        android:id="@+id/linear_reviews" 
 
        android:layout_width="0dp" 
 
        android:layout_height="wrap_content" 
 
        android:layout_weight="1" 
 
        android:gravity="center" 
 
        android:orientation="vertical" 
 
        android:padding="@dimen/view_size_normal"> 
 

 
        <com.tourwhiz.pro.widgets.TextViewLatoRegular 
 
         style="@style/TextViewTW" 
 
         android:layout_width="match_parent" 
 
         android:layout_height="wrap_content" 
 
         android:gravity="center" 
 
         android:text="@string/profile_reviews_text" 
 
         android:textSize="@dimen/text_size_large" /> 
 

 
        <com.tourwhiz.pro.widgets.TextViewLatoRegular 
 
         android:id="@+id/text_reviews_count" 
 
         style="@style/TextViewTW" 
 
         android:layout_width="match_parent" 
 
         android:layout_height="wrap_content" 
 
         android:gravity="center" 
 
         android:textSize="@dimen/text_size_large" 
 
         tools:text="12" /> 
 

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

 
    <android.support.v7.widget.RecyclerView 
 
     android:id="@+id/recycler_posts" 
 
     android:layout_width="match_parent" 
 
     android:layout_height="match_parent" 
 
     android:layout_gravity="bottom" 
 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" 
 
     tools:listitem="@layout/item_post" /> 
 

 

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

The blank bottom space is the problem

+0

如果您在.Could接受並給予好評呢?@MiguelS – KeLiuyue

回答

0

最後我找到了解決方法。我不知道它爲什麼起作用,但它確實如此。如果有人知道這是爲什麼,或者更好,爲什麼會發生這種情況,請回答這個問題,我會很樂意接受這個答案是正確的。

解決方法是將所述RecyclerView下方的空走圖。它爲我工作!

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

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/recycler_posts" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_gravity="bottom" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" 
     tools:listitem="@layout/item_post" /> 


</android.support.design.widget.CoordinatorLayout> 
    <View 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:visibility="gone" /> 
</android.support.design.widget.CoordinatorLayout> 
1

因爲你在RecyclerView設置android:layout_gravity="bottom"

刪除android:layout_gravity="bottom

+0

對不起的人我的回答是有用的,這無關我的問題。我試過了,這不是問題。 – MiguelS

1

解決方法建議在@KeLiuYue的回答中可能有效。

而且(如果上述修復失敗)有在很多情況下與設計的圖書館問題。所以有可能的情況下,當此修復程序可能不會因爲它的設計是小於屏幕高度的原因白色佈局工作空間,一些神祕的行爲在崩潰或展開<CollapsingToolbarLayout>。這個庫仍然存在bug,希望有一天可能會修復這個故障。

+0

也謝謝你的建議。 – KeLiuyue

+0

我已經閱讀過有關設計庫的問題,但我的簡潔:底部的空間總是等於爲CollapsingToolbarLayout聲明的minHeight。 – MiguelS