【问题标题】:RecyclerView places a horrible space between each elementRecyclerView 在每个元素之间放置了一个可怕的空间
【发布时间】:2020-07-14 01:19:36
【问题描述】:

嗨,你好吗?有人能帮我吗?

我想显示一个 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 android-recyclerview


    【解决方案1】:

    我在 1 年前遇到了这个错误。 尝试将android:layout_height="match_parent" 更改为android:layout_height="wrap_content"

    【讨论】:

    • 我已经回答了相同的解决方案,为什么您要应对给出相同的答案?
    • 对不起兄弟,我没有看到你的答案。发布答案后,您将看到它。
    • 非常感谢兄弟,这个解决方案对我帮助很大。
    【解决方案2】:

    我遇到了类似的问题,RelativeLayout 作为recyclerview 中每一行的根元素。我建议将视图布局更改为RelativeLayout

    要解决此问题,请找到包含每一行的 XML 文件,并确保根元素的高度为 wrap_content NOT match_parent。

    【讨论】:

    • 非常感谢兄弟,这个解决方案对我帮助很大,我也不知道后端图像已经损坏并且它们显示出来很丑,现在后端必须解决这个问题,我花了很多时间对于不是我的错的事情,我会尽快退出,我保证。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-10
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多