Android:RecyclerLayout正在添加默认填充

问题描述 投票:2回答:1

我正在尝试使用RecyclerLayout创建折叠工具栏布局。

问题是,当我在运行期间给布局充气时,它会在它自己的位置添加一个默认的填充。

下面是我的布局xmls:

activity_profile.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
   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"
   android:fitsSystemWindows="true">

   <android.support.v7.widget.RecyclerView
      android:id="@+id/recycler"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      app:layout_behavior="@string/appbar_scrolling_view_behavior" />

   <android.support.design.widget.AppBarLayout
      android:id="@+id/appbar"
      android:layout_width="match_parent"
      android:layout_height="180dp"
      android:fitsSystemWindows="true"
      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

       <android.support.design.widget.CollapsingToolbarLayout
           android:id="@+id/collapsing_toolbar"
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:fitsSystemWindows="true"
           app:contentScrim="?attr/colorPrimary"
           app:layout_scrollFlags="scroll|exitUntilCollapsed">

           <ImageView
               android:id="@+id/header"
               android:layout_width="match_parent"
               android:layout_height="match_parent"
               android:fitsSystemWindows="true"
               android:scaleType="centerCrop"
               app:layout_collapseMode="parallax" />

           <android.support.v7.widget.Toolbar
               android:id="@+id/toolbar"
               android:layout_width="match_parent"
               android:layout_height="?attr/actionBarSize"
               app:layout_collapseMode="pin"
               app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

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

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

   <android.support.design.widget.FloatingActionButton
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_margin="10dp"
       app:layout_anchor="@+id/appbar"
       app:layout_anchorGravity="bottom|center|end" />

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

我也试图删除activity_horizontal_margin但它似乎不起作用。

这是我试图在recycler-layout中膨胀的布局:

profile_view.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
    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.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorProfileStatsBackground"      
        app:layout_constraintBottom_toTopOf="@+id/guideline">

    </android.support.constraint.ConstraintLayout>

    <android.support.constraint.Guideline
        android:id="@+id/guideline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.25" />

</android.support.constraint.ConstraintLayout>

输出:

Final Output

android android-recyclerview recyclerview-layout
1个回答
0
投票

终于找到了问题所在。

问题在于AppBarLayout中的android:fitsSystemWindows="true"

我做了一些研究,发现了一篇文章fitsSystemWindow,它描述了这个属性的默认行为是它设置View的填充以确保内容不覆盖系统窗口。

© www.soinside.com 2019 - 2024. All rights reserved.