Пустое пространство между каждым элементом в представлении переработчика - PullRequest
0 голосов
/ 08 марта 2020

Я использую Firebase Recycler в своем приложении и реализовал код в своем фрагменте. Данные загружаются нормально, но когда я прокручиваю до конца списка, элементы получают пробелы между каждым и эти пробелы очищаются только при переходе от одного действия к другому.

Мой XML Код:

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="55dp">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/home_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary">

        <TextView
            android:id="@+id/map_view"
            android:layout_width="300dp"
            android:layout_height="wrap_content"
            android:drawableStart="@drawable/ic_location_on_black_24dp"
            android:drawablePadding="10dp"
            android:ellipsize="end"
            android:fontFamily="@font/roboto_medium"
            android:gravity="center"
            android:maxLines="1"
            android:padding="5dp"
            android:text="@string/text1" />

    </androidx.appcompat.widget.Toolbar>

    <androidx.cardview.widget.CardView
        app:cardCornerRadius="10dp"
        android:layout_margin="14dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <com.smarteist.autoimageslider.SliderView
            android:id="@+id/imageSlider"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            app:sliderAnimationDuration="5000"
            app:sliderAutoCycleEnabled="true"
            app:sliderIndicatorAnimationDuration="5000"
            app:sliderIndicatorGravity="center_horizontal|bottom"
            app:sliderIndicatorMargin="15dp"
            app:sliderIndicatorOrientation="horizontal"
            app:sliderIndicatorPadding="3dp"
            app:sliderIndicatorRadius="1dp"
            app:sliderIndicatorSelectedColor="#5A5A5A"
            app:sliderIndicatorUnselectedColor="#FFF"
            app:sliderScrollTimeInSec="3"
            app:sliderStartAutoCycle="true" />

    </androidx.cardview.widget.CardView>

    <RadioGroup
        android:id="@+id/layout_change_button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:gravity="center_horizontal"
        android:orientation="horizontal">


        <RadioButton
            android:id="@+id/btn_for_list1"
            android:layout_width="150dp"
            android:gravity="center"
            android:layout_height="30dp"
            android:background="@drawable/radio_flat_selector"
            android:button="@android:color/transparent"
            android:checked="true"
            android:text="Home Services"
            android:textColor="@color/radio_flat_text_selector" />

        <RadioButton
            android:id="@+id/btn_for_list2"
            android:gravity="center"
            android:layout_width="150dp"
            android:layout_height="30dp"
            android:background="@drawable/radio_flat_selector"
            android:button="@android:color/transparent"
            android:text="Home Improvements"
            android:textColor="@color/radio_flat_text_selector" />

    </RadioGroup>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/main_list1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="10dp"
            android:layout_marginEnd="10dp"
            android:layout_marginTop="15dp"/>

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/main_list2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:visibility="invisible"
            android:layout_marginStart="10dp"
            android:layout_marginEnd="10dp"
            android:layout_marginTop="15dp"/>
    </RelativeLayout>

</LinearLayout>

Код моего адаптера:

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.coderedinnovations.allioservices.R;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.firebase.ui.database.FirebaseRecyclerOptions;

public class MainList1_Adapter extends FirebaseRecyclerAdapter<MainList1, MainList1_Adapter.MainList1_Holder> {


    public MainList1_Adapter(@NonNull FirebaseRecyclerOptions<MainList1> options) {
        super(options);
    }

    @Override
    protected void onBindViewHolder(@NonNull MainList1_Holder holder, int position, @NonNull MainList1 model) {

        holder.heading_view.setText(model.getTitle());
        holder.desc_view.setText(model.getDescription());
        holder.offer_view.setText(model.getOffer());
        Glide.with(holder.image_view.getContext())
                .load(model.getImageLink())
                .into(holder.image_view);

    }

    @NonNull
    @Override
    public MainList1_Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
       View view = LayoutInflater.from(parent.getContext())
               .inflate(R.layout.main_item_card, parent, false);
       return new MainList1_Holder(view);
    }

    class MainList1_Holder extends RecyclerView.ViewHolder{

        TextView heading_view, desc_view, offer_view;
        ImageView image_view;
        public MainList1_Holder(@NonNull View itemView) {
            super(itemView);
            heading_view = itemView.findViewById(R.id.item_heading);
            desc_view = itemView.findViewById(R.id.item_description);
            offer_view = itemView.findViewById(R.id.item_offer);
            image_view = itemView.findViewById(R.id.item_image);
        }
    }

}

Посмотрите это видео, которое разъяснит мою проблему. Ссылка на видео

1 Ответ

1 голос
/ 09 марта 2020

Спасибо всем, кто пытался ответить на мой вопрос. Я только что допустил небольшую ошибку, которая дала пробелы между каждым элементом.

В макете Родителя элемента. Я добавил

android:layout_height:"match_parent"

вместо wrap_content, и это сделало ошибку.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...