1

我一直在尋找相當長的一段時間來解決這個問題,但沒有成功。我的AppBarLayout與我的一個xml文件中的RecyclerView重疊。我曾嘗試重新排列意見,但沒有任何積極的結果。任何幫助表示讚賞。這裏是我的代碼:AppBarLayout重疊RecyclerView

<android.support.v4.widget.DrawerLayout 
 
    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:id="@+id/drawer_layout" 
 
    android:layout_width="match_parent" 
 
    android:layout_height="match_parent" 
 
    android:fitsSystemWindows="true" 
 
    tools:openDrawer="start"> 
 

 
    <android.support.design.widget.CoordinatorLayout 
 
     xmlns:android="http://schemas.android.com/apk/res/android" 
 
     android:layout_width="match_parent" 
 
     android:layout_height="match_parent" 
 
     android:fitsSystemWindows="true" 
 
     android:background="@color/bg_register"> 
 

 
     <android.support.design.widget.AppBarLayout 
 
      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="?attr/actionBarSize" 
 
       android:background="@color/toolbar"/> 
 

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

 
     <include layout="@layout/content" 
 
       android:layout_width="match_parent" 
 
       android:layout_height="wrap_content" 
 
       android:id="@+id/x"/> 
 
    </android.support.design.widget.CoordinatorLayout> 
 

 
    <android.support.design.widget.NavigationView 
 
     android:id="@+id/nav_view" 
 
     android:layout_width="wrap_content" 
 
     android:layout_height="match_parent" 
 
     android:layout_gravity="start" 
 
     app:menu="@menu/activity_main_drawer" 
 
     android:clickable="true"/> 
 
</android.support.v4.widget.DrawerLayout>

這裏是內容的XML文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 
       xmlns:app="http://schemas.android.com/apk/res-auto" 
 
       android:layout_width="match_parent" 
 
       android:layout_height="match_parent" 
 
       xmlns:tools="http://schemas.android.com/tools" 
 
       app:layout_behavior="@string/appbar_scrolling_view_behavior" 
 
       android:orientation="vertical" 
 
       android:background="@color/bg_register" 
 
       android:paddingLeft="10dp" 
 
       android:paddingRight="10dp" 
 
       tools:showIn="@layout/activity"> 
 

 
    <TextView 
 
     android:padding="5dp" 
 
     android:id="@+id/textView" 
 
     android:layout_width="wrap_content" 
 
     android:layout_height="wrap_content" 
 
     android:text="@string/list" /> 
 

 
    <android.support.v7.widget.RecyclerView 
 
     android:layout_below="@id/textView" 
 
     android:layout_width="match_parent" 
 
     android:layout_height="match_parent" 
 
     android:id="@+id/lv_recycler" 
 
     android:background="@color/white" 
 
     android:scrollbars="vertical" 
 
     android:clickable="true" 
 
     android:fadeScrollbars="true"/> 
 

 
</RelativeLayout>

+0

你能粘貼一個截圖嗎? – suku

+0

它似乎是從我所知道的屏幕上推開工具欄。見圖:https://postimg.org/image/80mfleobl/ – BrownT

+0

它看起來很好。如果您覺得recyclerview觸摸屏幕底部,那麼只需爲recyclerview添加合適的'layout_marginBottom'即可。 – suku

回答

7

這個屬性添加到包括工具欄下面:

app:layout_behavior="@string/appbar_scrolling_view_behavior" 

當您使用CoordinatorLayoutAppBarLayout,你是爲協調滾動在工具欄上推的方式進行首次設置。但爲了得到它,你需要在工具欄下方的視圖中顯示appbar滾動視圖的行爲。這不僅設置了協調滾動,而且還通知CoordinatorLayout佈置較低視圖,以使其出現在工具欄下方。

如果您不希望協調一致的工具欄滾動,請將CoordinatorLayout替換爲垂直LinearLayout

+0

這工作得很好。謝謝! – BrownT

1

它看起來並不重疊。如果你想在兩者之間留有空格,只需在主XML文件中添加邊距。另外,從內容xml的根相對佈局中刪除方向,因爲它不起作用。

1

我有相同的重疊問題,但這樣做的原因是,我已經有

<android.support.constraint.ConstraintLayout 

因爲我的根ViewGroup中,不

<android.support.design.widget.CoordinatorLayout 

所以檢查是還有: )

相關問題