RecyclerView with a costum Adapter file

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

我在运行时得到了一个清晰的列表(布局之间没有空间),但是当我向下滚动时,所有内容都会受到干扰,并在要查看的布局之间形成一个大空间

完整项目

package com.example.recyclerview; 
// this is the code of the Adapter
//there is also a card class (datatype for the arraylist declared in mainActivity 

import android.content.Context;
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 java.util.ArrayList;

public class Adapter extends RecyclerView.Adapter<Adapter.ViewHolder> {
    Context context;
    ArrayList<card> arl ;
        public Adapter(Context context, ArrayList arl){
            this.context = context;
            this.arl = arl;
        }
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
       View view =  LayoutInflater.from(context).inflate(R.layout.card,parent,false);
       ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder ;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.img.setImageResource(arl.get(position).img);
        holder.name.setText(arl.get(position).name);
        holder.contact.setText(arl.get(position).contact);
    }

    @Override
    public int getItemCount() {
        return arl.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView img;
        TextView name;
        TextView contact;

        public ViewHolder(View itemView){
            super(itemView);
            name = itemView.findViewById(R.id.name);  
            img = itemView.findViewById(R.id.imageView);
            contact = itemView.findViewById(R.id.details);
        }

    }

}

期望有一个视图,其中滚动时两个视图之间的间距不能有任何变化

java android android-recyclerview recyclerlistview
© www.soinside.com 2019 - 2024. All rights reserved.