回收者视图中每个项目之间的空白

问题描述 投票:0回答:1

我在我的应用中使用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);
        }
    }

}

观看此视频,该视频将清楚地解释我的问题。Video Link

我在我的应用中使用Firebase Recycler,并且在片段中实现了代码。数据加载正常,但是当我滚动到列表的末尾时,各项之间会出现空格,并且空格会清除...

android firebase-realtime-database android-recyclerview recycler-adapter
1个回答
0
投票

感谢所有试图回答我的问题的人。我只是犯了一个小错误,使每个项目之间都留有空白。

© www.soinside.com 2019 - 2024. All rights reserved.