0

Подскажите пожалуйста, как можно уменьшить расстояние между элементами списка RecyclerView? Прокрутка сделана горизонтальная, через LinearLayoutManager введите сюда описание изображения

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="wrap_content"
    android:orientation="vertical"
    android:weightSum="1">
    <!-- A CardView that contains a TextView -->
    <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view"
        android:layout_width="310dp"
        android:layout_height="220dp"
        android:layout_gravity="left"
        android:layout_marginBottom="5dp"
        android:layout_marginTop="8dp"
        card_view:cardCornerRadius="5dp"
        card_view:cardElevation="5dp"
        card_view:contentPadding="10dp">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <ImageView
                android:id="@+id/iv_recycler_item"
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:layout_weight="1"
                tools:ignore="ContentDescription" />

        </LinearLayout>


    </android.support.v7.widget.CardView>
</LinearLayout>

1 ответ 1

1

Поменяйте android:layout_width у верхнего LinearLayout с match_parent на wrap_content:

<LinearLayout 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="wrap_content" <!-- вот здесь -->
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:weightSum="1">

Объясняю: каждый элемент создаётся отдельно по вашей разметке, и у вас получилось так, что родительский лейаут занимает по ширине всего уже своего родителя, которым выступает уже активити, и в итоге вы видите только один элемент на экране.

2
  • Добавил разметку 22 сен 2017 в 17:12
  • @Вячеслав дополнил ответ 22 сен 2017 в 17:12

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.