estoy teniendo un problema en un RecyclerView hecho con FirestoreRecyclerOptions donde estoy haciendo un pequeño chat. La idea es que el nombre del usuario salga alineado a la izquierda normalmente, pero si es un texto introducido por el mismo usuario que está accediendo, su nombre salga a la derecha.
Ésto me lo hace correctamente al inicio, pero se desalinea cuando hago scroll para arriba o para abajo.
Paso el onBindViewHolder ya que creo que el problema lo tengo ahí:
protected void onBindViewHolder(@NonNull ViewHolder holder, int position, @NonNull Chat chat) {
holder.mTxtUsuario.setText(chat.getUsuario());
holder.mTxtMensaje.setText(chat.getMensaje());
if (obtenerPerfil().getEmail().equals(chat.getEmail())) {
holder.mTxtUsuario.setTextColor(Color.RED);
holder.mTxtUsuario.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_END);
} else {
holder.mTxtUsuario.setTextColor(Color.parseColor("#0844C5"));
holder.mTxtUsuario.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START);
}
}
Paso también el xml del elemento por si acaso:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_margin="2dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Space
android:layout_width="match_parent"
android:layout_height="5dp" />
<TextView
android:id="@+id/txtUsuario"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#0844C5"
android:textStyle="bold"
android:textSize="12sp"/>
<TextView
android:id="@+id/txtMensaje"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="14sp"
android:layout_margin="3dp"
android:background="@drawable/borde_layout_gris"/>
</LinearLayout>
</LinearLayout>
Gracias :)
Al cargar el recycler:
Después de realizar scroll hacia arriba y abajo: