Recyclerview StaggeredGridLayoutManager无限滚动

时间:2018-08-24 14:21:37

标签: android firebase android-recyclerview infinite-scroll staggered-gridview

我想使用无限滚动,但是我做到了,但是如果我可以使用gridlayoutmanager,这是非常好的无限滚动,但是如果我使用staggeredlayout管理器,那总是滚动顶部,为什么? 当我成像高度匹配时,这非常好,但是我想使用包裹纸,请帮助 抱歉,我的英语不好

因为我的英语不太好,所以我不能正确地问这个问题。如果您不了解,我可以尝试修复它。 但是我的问题是,如果图片的高度不清楚,则无限滚动是个问题。

这是我的代码

 manager=new StaggeredGridLayoutManager(3,1);
    chat_rec_adapter=new recc_adapter(getActivity(),liste);
    recyclerView.setAdapter(chat_rec_adapter);
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(manager);

此代码在应用启动时运行

 private void setadapter() {
    Object query;


    DatabaseReference kref=ref.child("yarisma").child("kadın");
    Query mes=kref.orderByChild("timeeksi").limitToFirst( current_page*Total_item_load);

    mes.addChildEventListener(new ChildEventListener() {
        @Override
        public void onChildAdded(DataSnapshot dataSnapshot, String s) {

            itemposion++;
            liste.add(dataSnapshot.getValue(item_home.class));






            swipyRefreshLayout.setRefreshing(false);

            progressorta.setVisibility(View.VISIBLE);
            chat_rec_adapter.notifyDataSetChanged();
            gununtv.setVisibility(View.INVISIBLE);

        }

        @Override
        public void onChildChanged(DataSnapshot dataSnapshot, String s) {

        }

        @Override
        public void onChildRemoved(DataSnapshot dataSnapshot) {

        }

        @Override
        public void onChildMoved(DataSnapshot dataSnapshot, String s) {

        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });





}

在ı滚动此代码的底部

private void setmoreavdapter() {
        Object query;


        DatabaseReference kkref=ref.child("yarisma").child("kadın");


        Query mes=ref.child("yarisma").child("kadın").orderByChild("timeeksi").limitToFirst(current_page*Total_item_load);

        mes.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                for(DataSnapshot snapshot:dataSnapshot.getChildren()) {
                    itempp++;
                    if(itempp>itemposion){
                        liste.add(itemposion++,snapshot.getValue(item_home.class));


                        if(itemposion==current_page*Total_item_load) {
                            itempp=0;

                        }
                    }}


                chat_rec_adapter.notifyDataSetChanged();
                swipyRefreshLayout.setRefreshing(false);
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });

    }

这是我的适配器

public class recc_adapter extends RecyclerView.Adapter<recc_adapter.MyHolder> {


private Context context;
private List<item_home> liste;

public String gelenkey;



public boolean isSpeakButtonLongPressedd;

public recc_adapter(Context context, List<item_home> liste) {
    this.context = context;
    this.liste = liste;
}

@Override
public recc_adapter.MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {

    View view = LayoutInflater.from(context).inflate(R.layout.staggerd, parent, false);


    return new recc_adapter.MyHolder(view);


}


@Override
public void onBindViewHolder(final recc_adapter.MyHolder holder, int position) {

    final item_home itemhome = liste.get(position);

    Glide.with(context)
            .load(itemhome.getBitimg())
            .listener(new RequestListener<Drawable>() {
                @Override
                public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
                    return false;
                }

                @Override
                public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {


                    return false;
                }
            })
            .into(holder.image);




}


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

public class MyHolder extends RecyclerView.ViewHolder {

    AppCompatImageView image;


    public MyHolder(View itemView) {
        super(itemView);


        image = itemView.findViewById(R.id.simpl);

    }
}

}

0 个答案:

没有答案