我使用FirebaseRecycleAdapter从Firebase RealtimeDatabase加载聊天数据。 我希望以两种方式显示消息,因此左图像与右图像不同。
但是图像有时会像图片一样错位。
这是我的代码:
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正常工作CircleImageView。看起来像上下文:OneToOneChatActivity.this当我使用代码时:Glide.with(....)是错误的,但我无法找出解决方案。 我怎样才能使它有效?
答案 0 :(得分:1)
我发现了我的问题。有两种方法可以解决问题
所以在这篇文章中,在“else”的情况下,你可以为imageView设置透明色以避免问题