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 

所以检查是还有: )

相关问题