Android RecyclerView在每个元素之间放置了一个可怕的空格
嗨,你好吗?有人能帮我吗 我想显示一个RecyclerView,并让项目一个接一个地显示 但是我不明白为什么在每个元素之间都会出现一个可怕的空间,就像你在这张图片中看到的那样 我想在没有空白的情况下显示recycler视图的所有元素 以下是我使用的xml cardviewAndroid RecyclerView在每个元素之间放置了一个可怕的空格,android,layout,android-recyclerview,Android,Layout,Android Recyclerview,嗨,你好吗?有人能帮我吗 我想显示一个RecyclerView,并让项目一个接一个地显示 但是我不明白为什么在每个元素之间都会出现一个可怕的空间,就像你在这张图片中看到的那样 我想在没有空白的情况下显示recycler视图的所有元素 以下是我使用的xml cardview <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http
<?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" />
我遇到了一个类似的问题,RelativeLayout
作为recyclerview
中每一行的根元素。我建议将视图布局更改为RelativeLayout
要解决此问题,请找到包含每一行的XML文件,并确保根元素的高度为wrap\u content
NOT match\u parent.我在一年前遇到此错误。
尝试将android:layout\u height=“match\u parent”
更改为android:layout\u height=“wrap\u content”
我已经回答了相同的解决方案为什么你要给出相同的答案?抱歉,兄弟,我没有看到你的答案。在发布答案后,你会看到的。非常感谢兄弟,这个解决方案帮了我很多。非常感谢朋友,这个解决方案帮了我很多,我也不知道后端图像已经损坏,它们显示出丑陋,现在后端必须解决这个问题,我花了这么多时间做了一些不是我的错的事情,我很快就会退出,我保证。
<?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>