RecyclerView помещает ужасное пространство между каждым элементом - PullRequest
0 голосов
/ 02 апреля 2020

Привет, как дела? Кто-нибудь может мне помочь?

Я хочу отобразить RecyclerView и сделать так, чтобы элементы отображались один за другим.

Но я не понимаю, почему ужасное пространство между каждым из элементов отображается ужасным образом, когда вы можно видеть на этом изображении.

phone screenshot trouble

Я хочу показать все элементы представления переработчика без пробелов.

Здесь мои 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>

Я ценю любые советы или предложения

Ответы [ 2 ]

1 голос
/ 02 апреля 2020

Я столкнулся с этой ошибкой 1 год go. Попробуйте изменить android:layout_height="match_parent" на android:layout_height="wrap_content"

0 голосов
/ 02 апреля 2020

Я столкнулся с аналогичной проблемой, с RelativeLayout в качестве элемента root для каждой строки в recyclerview. Я предлагаю изменить макет представления на RelativeLayout.

. Чтобы решить эту проблему, найдите файл XML, содержащий каждую строку, и убедитесь, что высота элемента root равна wrap_content NOT match_parent.

...