我在我的应用程序中使用ChatKit库 ( https://github.com/stfalcon-studio/ChatKit/ ) 作为聊天功能。在图书馆提供的消息列表中,我还包括了图片消息。
它工作正常,但气泡的图像布局不明确,如下图:
气泡图 1 和 3 应该在右侧对齐,但它们在传入消息的可用空间中粘在左侧。
请注意,默认文本消息气泡在右侧正确显示。
我没有在库中找到任何用于配置此行为的布局属性。
这是我的消息列表 XML:
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_comments"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.stfalcon.chatkit.messages.MessagesList
android:id="@+id/messagesList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/input_comment"
app:incomingDefaultBubbleColor="@color/lightGrayRetail"
app:incomingTimeTextColor="@color/white"
app:incomingDefaultBubblePressedColor="@color/lightGrayRetail"
app:incomingDefaultImageOverlayPressedColor="@color/lightGrayRetail"
app:outcomingDefaultBubblePressedColor="@color/pinkRetail"
app:outcomingDefaultImageOverlayPressedColor="@color/pinkRetail"
app:outcomingDefaultBubbleColor="@color/pinkRetail"
app:outcomingTimeTextColor="@color/colorMaterialGray" />
</android.support.v4.widget.SwipeRefreshLayout>
我收到的短信布局布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp">
<TextView
android:id="@+id/displayNameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/bubble"
android:layout_marginStart="8dp"
android:layout_marginBottom="8dp"
android:textColor="@color/colorMaterialGray"/>
<de.hdodenhof.circleimageview.CircleImageView
android:id="@id/messageUserAvatar"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginEnd="8dp"
android:src="@drawable/woman" />
<ImageView
android:id="@+id/onlineIndicator"
android:layout_width="12dp"
android:layout_height="12dp"
android:layout_alignEnd="@id/messageUserAvatar"
android:layout_alignTop="@id/messageUserAvatar"
android:layout_marginEnd="5dp" />
<LinearLayout
android:id="@id/bubble"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="30dp"
android:layout_below="@+id/displayNameTextView"
android:layout_toEndOf="@id/messageUserAvatar"
android:orientation="vertical">
<TextView
android:id="@id/messageText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:layout_marginStart="8dp"/>
</LinearLayout>
<TextView
android:id="@+id/incomingTimeTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="@id/bubble"
android:layout_below="@id/bubble"
android:layout_marginEnd="4dp"
android:text="18:00"
android:layout_marginTop="4dp"
android:textColor="@color/colorMaterialGray" />
</RelativeLayout>
输出布局:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp">
<LinearLayout
android:id="@id/bubble"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginStart="40dp"
android:orientation="vertical">
<TextView
android:id="@id/messageText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<TextView
android:id="@+id/outcomingTimeTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@id/bubble"
android:layout_below="@id/bubble"
android:textColor="@color/colorMaterialGray"
android:layout_marginStart="16dp"/>
</RelativeLayout>
输出的MessageHolder:
public class CustomOutcomingMessageViewHolder extends MessageHolders.OutcomingTextMessageViewHolder<Comment> {
private TextView mOutcomingTimeTextView;
public CustomOutcomingMessageViewHolder(View itemView) {
super(itemView);
mOutcomingTimeTextView = itemView.findViewById(R.id.outcomingTimeTextView);
}
@Override
public void onBind(Comment comment) {
super.onBind(comment);
if(comment.getmContent() != null){
if(comment.getmContent().length() > 3){
SimpleDateFormat timeOutput = new SimpleDateFormat("HH:mm", Locale.FRANCE);
String commentPostedTime = timeOutput.format(comment.getmPostedDate());
mOutcomingTimeTextView.setText(commentPostedTime);
}
}
}
}
有任何想法吗 ?