0
我使用FirebaseRecycleAdapter從Firebase RealtimeDatabase加載聊天數據。 我想在兩個方向上顯示消息,所以左側圖像與右側圖像不同。帶Glide(或Picasso)的FirebaseRecycleAdapter在錯誤位置加載圖像
但圖像有時會像圖片一樣錯位。
這裏是我的代碼:
mFirebaseAdapter = new FirebaseRecyclerAdapter<Message, MessageViewHolder>(
Message.class,
R.layout.item_message_onetoone,
MessageViewHolder.class,
databaseReference.child(Constant.CHILD_CHATONETOONE).child(myUid).child(clientUid)) {
@Override
protected void populateViewHolder(MessageViewHolder viewHolder, Message message, int position) {
String senderUid= message.getSenderUid();
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(RecyclerView.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT);
lp.leftMargin= 10;
lp.rightMargin= 10;
viewHolder.messageTextView.setText(message.getMessage());
if (senderUid.equals(myUid)){
lp.gravity= Gravity.RIGHT;
viewHolder.linearLayout.setLayoutParams(lp);
Glide.with(OneToOneConversationActivity.this).load(myPhotoURL).into(viewHolder.messengerImageView);
viewHolder.messengerTextView.setText(myName);
}
else if(senderUid.equals(clientUid)){
lp.gravity= Gravity.LEFT;
viewHolder.linearLayout.setLayoutParams(lp);
viewHolder.messengerTextView.setText(clientName);
}
}
};
MessageViewHolder類:
public static class MessageViewHolder extends RecyclerView.ViewHolder {
public TextView messageTextView;
public TextView messengerTextView;
public CircleImageView messengerImageView;
public LinearLayout linearLayout;
public MessageViewHolder(View v) {
super(v);
messageTextView = (TextView) itemView.findViewById(R.id.messageTextView);
messengerTextView = (TextView) itemView.findViewById(R.id.messengerTextView);
messengerImageView = (CircleImageView) itemView.findViewById(R.id.messengerImageView);
linearLayout= (LinearLayout) itemView.findViewById(R.id.llOneToOneChat);
}
}
的的LinearLayout和textViews工作正常exept CircleImageView。這似乎是上下文:OneToOneChatActivity.this當我使用代碼:Glide.with(....)是錯誤的,但我無法找出解決方案。 我怎樣才能讓它工作的財產?
嘗試使用其他的,而不是如果 – elmontoya7
@ elmontoya7沒有變化:( –