Android Firebase:聊天消息背景重叠



聊天消息的背景在使用FireBaseRecyCyclerAdapter显示所有消息时,一直在重叠。这是我遇到的错误

**这是MessageCard

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/chattttt_linearlayout"
    android:gravity="end">
    <android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:layout_width="wrap_content"
        card_view:cardCornerRadius="10dp"
        card_view:contentPadding="10dp"
        card_view:cardElevation="4dp"
        card_view:cardMaxElevation="6dp"
        android:layout_gravity="end"
        android:id="@+id/carddddd"
        android:layout_height="wrap_content"
        android:layout_margin="3dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/sender_text_right"
                android:text="Hi , How are you?"
                android:padding="5dp"
                android:maxWidth="250dp"
                android:textSize="20sp" />
        </LinearLayout>
    </android.support.v7.widget.CardView>
</LinearLayout>

**这是chatactivity firebaseRecyclerAdapter

@Override
protected void onStart() {
    super.onStart();
    final FirebaseRecyclerAdapter<Chat, MessageViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Chat, MessageViewHolder>(
            Chat.class,
            R.layout.message_card_right,
            MessageViewHolder.class,
            messagesDatabase
    ) {

        @Override
        protected void populateViewHolder(MessageViewHolder viewHolder, Chat model, final int position) {
            viewHolder.setTextt(model.getText());
            isMe = model.getUid();
            if (isMe != null && !isMe.equals(currentCustomerUID)) {
                viewHolder.messageLinearLayout.setGravity(Gravity.START);
                viewHolder.messageText.setTextColor(getResources().getColor(android.R.color.black));
            } else {
                viewHolder.messageLinearLayout.setGravity(Gravity.END);
                viewHolder.messageText.setTextColor(getResources().getColor(android.R.color.white));
                viewHolder.messageCardView.setBackgroundResource(R.drawable.bubble_in);
            }
        }

    };
    MessageList.setAdapter(firebaseRecyclerAdapter);

}

我认为您还应该添加此行,以确保您的CardView获取您的首选背景资源:

        if (isMe != null && !isMe.equals(currentCustomerUID)) {
            ....
            viewHolder.messageCardView.setBackgroundResource(R.drawable.bubble_out);
        } else {
            ...
        }

不要忘记将R.drawable.bubble_out替换为您自己的可绘制资源。我也遇到了这个问题,这就是我所做的。从那以后没事。

相关内容

  • 没有找到相关文章

最新更新