Desplácese hasta la parte inferior de recyclerview con varios tipos de vista

Tengo un recyclerview con varios artículos. Y reciclerview tiene diferentes tipos de vista con diferentes alturas ..

Así que esto es lo que he intentado

recyclerview.scrollToPosition(adapterWrapper.getAdapter().getItemCount()-1); 

y

 app:layoutManager="LinearLayoutManager" app:stackFromEnd="true" 

Funcionan bien para mí cuando los aplico en tipos de vista única solamente .. Pero en tipos multiview. No se desplaza hacia abajo. Está siendo atascado en 9 artículos antes de la parte inferior.

Yo estaba usando stackFromBottom en listview antes y estaba funcionando bien ..

Entonces, ¿cuál es la solución para ello en recyclerview?

En realidad es una aplicación de chat con diferentes tipos de diseño, incluyendo imágenes, gif, etc.

Código RecyclerAdapter,

 package com.buckydroid.anonchat.Adapters; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.webkit.URLUtil; import android.widget.ImageView; import android.widget.PopupMenu; import android.widget.TextView; import android.widget.Toast; import com.buckydroid.anonchat.Async.DownloadManager; import com.buckydroid.anonchat.Chatroom.ChatRoom; import com.buckydroid.anonchat.Pages.FullScreenImageView; import com.buckydroid.anonchat.Pages.Profile; import com.buckydroid.anonchat.Pages.VideoPlayer; import com.buckydroid.anonchat.R; import com.bumptech.glide.Glide; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.resource.drawable.GlideDrawable; import com.bumptech.glide.load.resource.gif.GifDrawable; import com.bumptech.glide.request.RequestListener; import com.bumptech.glide.request.target.GlideDrawableImageViewTarget; import com.bumptech.glide.request.target.Target; import com.firebase.client.DataSnapshot; import com.firebase.client.Firebase; import com.firebase.client.FirebaseError; import com.firebase.client.ValueEventListener; import com.google.firebase.auth.FirebaseAuth; import com.google.firebase.database.DatabaseError; import com.google.firebase.database.FirebaseDatabase; import com.vanniktech.emoji.EmojiTextView; import java.net.URL; import java.net.URLConnection; import java.util.ArrayList; import java.util.List; import de.hdodenhof.circleimageview.CircleImageView; /** * Created by buckydroid on 27/04/17. */ public class ChatRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{ List<String> message = new ArrayList<>(); List<Integer> image = new ArrayList<>(); List<String> usernames = new ArrayList<>(); List<String> keys = new ArrayList<>(); ChatRoom chatroom = new ChatRoom(); String name; Context c; String username; String otherusername; String groupName; public GifDrawable gifDrawable; List<Integer> type = new ArrayList<>(); String id; ArrayList<String> zcode = new ArrayList<>(); public ChatRecyclerAdapter(String id, String s, List<String> message, List<Integer> image, Context c, String username, String otherusername, List<Integer> type, List<String> usernames, String j, ArrayList<String> zcode) { this.message = message; this.image = image; this.c = c; this.username = username; this.otherusername = otherusername; this.type = type; this.usernames = usernames; this.groupName = j; this.name = s; this.id = id; this.zcode = zcode; } class ViewHolder extends RecyclerView.ViewHolder{ ImageView imageView; EmojiTextView messageView; CircleImageView profileImage; ImageView gif; TextView groupactionmessage; ImageView thumbnail; TextView filename; TextView filesize; TextView morevert; public ViewHolder(View itemView) { super(itemView); messageView = (EmojiTextView) itemView.findViewById(R.id.message_view); imageView = (ImageView) itemView.findViewById(R.id.imageMessage); profileImage = (CircleImageView) itemView.findViewById(R.id.profile_image); thumbnail = (ImageView) itemView.findViewById(R.id.thumbnail); filename = (TextView) itemView.findViewById(R.id.filename); gif = (ImageView) itemView.findViewById(R.id.gifmessage); groupactionmessage = (TextView) itemView.findViewById(R.id.group_action_message); } } @Override public int getItemViewType(int position) { if (username.equals(usernames.get(position))) { Log.i("type", String.valueOf(type.get(position))); return type.get(position); } else return type.get(position)+7; } @Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View v = null; switch (viewType){ case 0: v = LayoutInflater.from (parent.getContext ()).inflate (R.layout.sender_message_bubble, parent, false); System.out.println("Type 0"); return new ViewHolder(v); case 7: v = LayoutInflater.from (parent.getContext ()).inflate (R.layout.message_item, parent, false);; System.out.println("Type 7"); return new ViewHolder(v); case 1: v = LayoutInflater.from (parent.getContext ()).inflate (R.layout.sender_image_layout, parent, false); System.out.println("Type 1"); return new ViewHolder(v); case 8: v = LayoutInflater.from (parent.getContext ()).inflate (R.layout.chatroom_image, parent, false); System.out.println("Type 8"); return new ViewHolder(v); case 2: v = LayoutInflater.from (parent.getContext ()).inflate (R.layout.sender_gif, parent, false); System.out.println("Type 2"); return new ViewHolder(v); case 9: v = LayoutInflater.from (parent.getContext ()).inflate (R.layout.chatroom_gif, parent, false); System.out.println("Type 9"); case 3: v = LayoutInflater.from (parent.getContext ()).inflate (R.layout.group_actions_list, parent, false); System.out.println("Type 3"); return new ViewHolder(v); case 10: v = LayoutInflater.from (parent.getContext ()).inflate (R.layout.group_actions_list, parent, false); System.out.println("Type 10"); return new ViewHolder(v); case 4: v = LayoutInflater.from (parent.getContext ()).inflate (R.layout.video_thumbnail_message, parent, false); System.out.println("Type 4"); return new ViewHolder(v); case 11: v = LayoutInflater.from (parent.getContext ()).inflate (R.layout.video_thumbnail_message2, parent, false); System.out.println("Type 11"); return new ViewHolder(v); case 5: v = LayoutInflater.from (parent.getContext ()).inflate (R.layout.file_layout, parent, false); System.out.println("Type 5"); return new ViewHolder(v); case 12: v = LayoutInflater.from (parent.getContext ()).inflate (R.layout.sender_file_layout, parent, false); System.out.println("Type 12"); return new ViewHolder(v); default: v = LayoutInflater.from (parent.getContext ()).inflate (R.layout.message_item, parent, false); return new ViewHolder(v); } } @Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { switch (holder.getItemViewType()){ case 0: case 7: Log.i("Type on message", String.valueOf(type.get(position)) + " " +message.get(position) + " "+holder.getItemViewType()); ViewHolder messageHolder = (ViewHolder)holder; if (!username.equals(usernames.get(position))) messageHolder.profileImage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(c, Profile.class); i.putExtra("username",usernames.get(position)); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); c.startActivity(i); } }); Firebase userdata = new Firebase("https://droidchatz.firebaseio.com/userdata/"+usernames.get(position)); userdata.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { if (!usernames.get(position).equals(username)) Glide.with (c.getApplicationContext()) .load (dataSnapshot.child("pic").getValue(String.class)) .diskCacheStrategy(DiskCacheStrategy.ALL) .error (R.drawable.dog) .into (messageHolder.profileImage); } @Override public void onCancelled(FirebaseError firebaseError) { } }); messageHolder.messageView.setText(message.get(position)); messageHolder.messageView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { PopupMenu popupMenu = new PopupMenu(c, messageHolder.messageView); popupMenu.getMenuInflater().inflate(R.menu.messsage_popup_menu, popupMenu.getMenu()); popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.action_reply: String te = usernames.get(position) + " : " + messageHolder.messageView.getText() + "\n\n\n"; ChatRoom.input.setText(te); ChatRoom.input.setSelection(te.length()); break; case R.id.action_copy: android.content.ClipboardManager clipboard = (android.content.ClipboardManager) c.getSystemService(Context.CLIPBOARD_SERVICE); android.content.ClipData clip = android.content.ClipData.newPlainText(messageHolder.messageView.getText(), messageHolder.messageView.getText()); clipboard.setPrimaryClip(clip); Toast.makeText(c, "Text Copied...", Toast.LENGTH_SHORT).show(); break; case R.id.action_report: new Firebase("https://droidchatz.firebaseio.com/groupchat/" + name).child("report").child(usernames.get(position)).child(FirebaseAuth.getInstance().getCurrentUser().getUid()).setValue(true); break; } return false; } }); popupMenu.show(); return false; } }); break; case 1: case 8: ViewHolder imageHolder = (ViewHolder)holder; Log.i("Type on image", String.valueOf(type.get(position)) + " " +message.get(position)+" "+holder.getItemViewType()); imageHolder.imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(c, FullScreenImageView.class); i.putExtra("uri", message.get(position)); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); c.startActivity(i); } }); imageHolder.imageView.setAdjustViewBounds(true); GlideDrawableImageViewTarget imageViewPreview = new GlideDrawableImageViewTarget(imageHolder.imageView); Glide .with(c) .load(message.get(position)) .centerCrop() .listener(new RequestListener<String, GlideDrawable>() { @Override public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) { return false; } @Override public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { return false; } }) .into(imageViewPreview); Firebase userdata2 = new Firebase("https://droidchatz.firebaseio.com/userdata/"+usernames.get(position)); userdata2.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { if (!usernames.get(position).equals(username)) { Glide.with (c) .load (dataSnapshot.child("pic").getValue(String.class)) .error (R.drawable.dog) .into (imageHolder.profileImage); } } @Override public void onCancelled(FirebaseError firebaseError) { } }); break; case 2: case 9: Log.i("Type on gif", String.valueOf(type.get(position)) + " " +message.get(position)+" "+holder.getItemViewType()); ViewHolder gifHolder = (ViewHolder)holder; gifHolder.gif.setAdjustViewBounds(true); GlideDrawableImageViewTarget imageViewPreview2 = new GlideDrawableImageViewTarget(gifHolder.gif); Glide .with(c) .load(message.get(position)) .listener(new RequestListener<String, GlideDrawable>() { @Override public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) { return false; } @Override public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { return false; } }) .into(imageViewPreview2); if (!username.equals(usernames.get(position))) gifHolder.profileImage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(c, Profile.class); i.putExtra("username",usernames.get(position)); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); c.startActivity(i); } }); Firebase userdata3 = new Firebase("https://droidchatz.firebaseio.com/userdata/"+usernames.get(position)); userdata3.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { if (!usernames.get(position).equals(username)) Glide.with (c) .load (dataSnapshot.child("pic").getValue(String.class)) .error (R.drawable.dog) .into (gifHolder.profileImage); } @Override public void onCancelled(FirebaseError firebaseError) { } }); break; case 3: case 10: Log.i("Type on action", String.valueOf(type.get(position)) + " " +message.get(position)+" "+holder.getItemViewType()); ViewHolder actionHolder = (ViewHolder)holder; actionHolder.groupactionmessage.setText(message.get(position)); break; case 4: case 11: ViewHolder videoHolder = (ViewHolder)holder; Log.i("Type on video", String.valueOf(type.get(position)) + " " +message.get(position)+" "+holder.getItemViewType()); FirebaseDatabase.getInstance().getReference().child("thumbnails").child(name).child(zcode.get(position)).addValueEventListener(new com.google.firebase.database.ValueEventListener() { @Override public void onDataChange(com.google.firebase.database.DataSnapshot dataSnapshot) { Glide.with(c).load(dataSnapshot.getValue(String.class)).centerCrop().into(videoHolder.thumbnail); } @Override public void onCancelled(DatabaseError databaseError) { } }); if (!username.equals(usernames.get(position))) videoHolder.profileImage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(c, Profile.class); i.putExtra("username",usernames.get(position)); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); c.startActivity(i); } }); videoHolder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(c, VideoPlayer.class); i.putExtra("link", message.get(position)); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); c.startActivity(i); } }); Firebase userdata4 = new Firebase("https://droidchatz.firebaseio.com/userdata/"+usernames.get(position)); userdata4.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { if (!usernames.get(position).equals(username)) Glide.with (c) .load (dataSnapshot.child("pic").getValue(String.class)) .error (R.drawable.dog) .into (videoHolder.profileImage); } @Override public void onCancelled(FirebaseError firebaseError) { } }); break; case 5: case 12: ViewHolder fileHolder = (ViewHolder)holder; Firebase userdata5 = new Firebase("https://droidchatz.firebaseio.com/userdata/"+usernames.get(position)); if (!username.equals(usernames.get(position))) fileHolder.profileImage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(c, Profile.class); i.putExtra("username",usernames.get(position)); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); c.startActivity(i); } }); userdata5.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { if (!usernames.get(position).equals(username)) Glide.with (c) .load (dataSnapshot.child("pic").getValue(String.class)) .error (R.drawable.dog) .into (fileHolder.profileImage); } @Override public void onCancelled(FirebaseError firebaseError) { } }); fileHolder.filename.setText(URLUtil.guessFileName(message.get(position), null, null)); final URL[] uri = new URL[1]; final URLConnection[] ucon = new URLConnection[1]; final String[] contentLengthStr = new String[1]; Thread size = new Thread(); Runnable getfilesize; fileHolder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(message.get(position))); c.startActivity(browserIntent); } }); break; } } @Override public int getItemCount() { return message.size(); } } 

¡Gracias !!!

2 Solutions collect form web for “Desplácese hasta la parte inferior de recyclerview con varios tipos de vista”

No sé la razón, pero cambié mi altura de RecyclerView a match_parent y está trabajando correctamente.

Y es el desplazamiento para completar el fondo y todavía estoy usando la misma función .setstacktoend(true)

Gracias a todos los que intentaron ayudarme 🙂

Puede mostrarnos su código completo de recyclerview y su adaptador.

Tal vez esto funcionará

Recyclerview.scrollToPosition (mData.size () – 1);

Donde mData es la lista que está pasando en el adaptador de recyclerview es bastante difícil de averiguar lo que está mal con un código tan pequeño.

  • Java.lang.NullPointerException en android.support.v7.widget.RecyclerView.onMeasure
  • Actualizar la barra de progreso en Recyclerview
  • Obtener elementos visibles en RecyclerView
  • Decoración RecyclerView (con GridLayoutManager) para mostrar el divisor entre los elementos
  • RecylcerView se desplaza a la parte superior del elemento eliminado
  • Cómo recorrer los elementos en Android RecyclerView?
  • Encabezado RecyclerView bajo elementos de Android
  • RecyclerView vuelve a calcular WRAP_CONTENT
  • RecyclerView Infinite Scroll escucha que se llama dos veces
  • Cómo implementar coverflow con recyclerview
  • Cómo agregar consistentemente fondos alternativos a las vistas de elementos en RecyclerView
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.