android - RecyclerView 在每个元素之间放置了一个可怕的空间
问题描述
嗨,你好吗?有人能帮我吗?
我想显示一个 RecyclerView 并让项目一个接一个地显示。
但是我不明白为什么每个元素之间都以一种可怕的方式显示了一个可怕的空间,就像你在这张图片中看到的那样。
我想显示没有空白的回收站视图的所有元素。
这是我使用的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:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<View
android:id="@+id/gradient"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/vertical_gradient_up"
android:elevation="1dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="@id/guideLine2"
/>
<ImageView
android:id="@+id/image"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:contentDescription="México"
android:scaleType="centerCrop"
android:src="@drawable/place_holder"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintVertical_bias="1.0"
app:srcCompat="@color/white"
/>
<TextView
android:id="@+id/brand_news"
style="@style/App"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:maxLines="3"
android:minLines="1"
android:textColor="#ffffffff"
app:layout_constraintStart_toStartOf="parent"
android:elevation="2dp"
android:text="BRAND NEWS"
android:textSize="30sp"
app:layout_constraintTop_toBottomOf="@+id/guideLine2"
app:layout_constraintBottom_toTopOf="@+id/title"
/>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:maxLines="1"
android:minLines="1"
android:textColor="#ffffffff"
app:layout_constraintStart_toStartOf="parent"
android:elevation="2dp"
android:text="Title"
android:textSize="30sp"
app:layout_constraintTop_toBottomOf="@+id/brand_news"
app:layout_constraintBottom_toTopOf="@+id/body"
/>
<TextView
android:id="@+id/body"
style="@style/App"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:maxLines="3"
android:minLines="1"
android:textColor="#ffffffff"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/title"
app:layout_constraintBottom_toTopOf="@+id/date"
android:elevation="2dp"
android:text="Subtitle
android:textSize="20sp"
/>
<TextView
android:id="@+id/date"
style="@style/App"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:maxLines="1"
android:minLines="1"
android:textColor="#ffffffff"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/body"
app:layout_constraintBottom_toBottomOf="parent"
android:elevation="2dp"
android:text="Fecha de la noticia"
android:textSize="15sp"
/>
<android.support.constraint.Guideline
android:id="@id/guideLine2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.7"
/>
<android.support.constraint.Guideline
android:id="@+id/guideLine3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5" />
活动
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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/contentView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".SectionFeed.ExperiencesFeed"
>
<FrameLayout
android:id="@+id/loaderMask"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.6"
android:background="@color/black"
android:elevation="1dp"
android:visibility="invisible">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/loaderImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:elevation="3dp"
android:scaleX="0.7"
android:scaleY="0.7" />
</RelativeLayout>
</FrameLayout>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawerMenu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="10">
<android.support.constraint.ConstraintLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="@+id/hedaer"
style="@style/header"
android:layout_width="match_parent"
android:layout_height="@dimen/headerSize"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
<include
layout="@layout/static_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</FrameLayout>
<LinearLayout
android:id="@+id/followHeader"
style="@style/headerLayout"
android:layout_width="match_parent"
android:layout_height="@dimen/title_header"
android:background="@drawable/view_underlined_black"
android:orientation="horizontal"
app:layout_constraintTop_toBottomOf="@+id/hedaer"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
<TextView
android:id="@+id/surveyTitle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@string/encuestas_titulo"
android:textSize="@dimen/title_font_size" />
<LinearLayout
style="generalPaddingStart"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal"
android:paddingStart="20dp">
<View
android:layout_width="wrap_content"
android:layout_height="2px"
android:background="@color/black" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/pushNotification"
android:layout_width="match_parent"
android:layout_height="@dimen/title_header"
android:orientation="horizontal"
app:layout_constraintTop_toBottomOf="@id/followHeader"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerViewExperiencesFeed"
tools:listitem="@layout/cardview_experience_general_feed"
tools:itemCount="5"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@id/pushNotification"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@+id/assistFooter"
android:orientation="horizontal"
android:minHeight="300dp"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"
/>
<LinearLayout
android:id="@+id/assistFooter"
android:layout_width="match_parent"
android:layout_height="@dimen/footerSize"
android:orientation="vertical"
app:layout_constraintTop_toBottomOf="@id/recyclerViewExperiencesFeed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
>
<FrameLayout
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="@dimen/footerSize"
android:gravity="bottom"
android:orientation="horizontal">
<include
layout="@layout/static_footer_contact_btn"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
<!-- The navigation drawer -->
<RelativeLayout
android:id="@+id/leftMenu"
android:layout_width="320dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/white"
android:divider="@android:color/transparent"
android:dividerHeight="0dp">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
layout="@layout/menu"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
</FrameLayout>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
我感谢任何意见或建议
解决方案
一年前我遇到了这个错误。尝试更改android:layout_height="match_parent"
为android:layout_height="wrap_content"
推荐阅读
- bash - 将命令的输出分配给变量的问题
- python - 计算日期之间的天数,使用 pyspark 忽略周末
- java - 执行命令行等效于 Runtime.getRuntime().exec(cmd); 在 JNI C 中
- c# - 通过将对象列表与另一个列表进行比较,从对象列表中删除条目
- javascript - 拖放元素时HTML拖放api不起作用(反应)
- python-3.x - 拆分涉及括号的字符串,同时保留括号
- openshift - Maven / Fabric8 - 针对远程 OpenShift 安装构建 OpenShift 容器映像
- reactjs - 我正在尝试使用 React Hooks 和 Webpack 构建 NPM 模块,因此在我尝试使用发布包后,它会给出 Invalid Hook call Error
- python - 如何获得二维 Numpy 数组中的秩
- javascript - 将 React 组件转换为 PNG/PDF 的最佳库?