在我的应用程序中,当用户发送或接收图像时,如果用户滚动离开该图像并向后滚动到该图像,则该图像将变得不可见,从而使该图像的最后位置为空,从而弄乱了视图。当用户关闭ChatActivity
并将其重新打开时,该图像会重新出现。
所以我现在的问题是,即使用户滚动到顶部和背面,我如何也可以始终将图像保持在其位置上?
这是我发送的邮件持有人
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:paddingTop="8dp">
<TextView
android:id="@+id/text_message_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="4dp"
android:text="11:40"
android:textColor="@color/colorPrimaryy"
android:textSize="10sp"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="@+id/text_message_body"
app:layout_constraintRight_toLeftOf="@+id/text_message_body" />
<TextView
android:id="@+id/text_message_body"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
android:background="@drawable/sent_message_bubble"
android:padding="10dp"
android:text="hello, hello!"
android:textColor="#080000"
android:textSize="17sp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/read_reciept"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="28dp"
android:text="seen"
android:textStyle="bold|italic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/text_message_body"
app:layout_constraintVertical_bias="0.0" />
<ImageView
android:id="@+id/message_sent_image_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginStart="0dp"
android:maxWidth="240dp"
android:background="@drawable/sent_message_bubble"
android:padding="0dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:scaleType="fitEnd" />
</android.support.constraint.ConstraintLayout>
这是消息适配器
void bind(Messages message) {
String user_id = message.getFrom();
String message_type = message.getType();
boolean seen = message.isSeen();
if (message_type.equals("text")) {
if (seen){
readReciept.setVisibility(View.VISIBLE);
}else {
readReciept.setVisibility(View.INVISIBLE);
}
messageText.setText(message.getMessage());
// Format the stored timestamp into a readable String using method.
timeText.setText(DateUtils.formatDateTime(message.getTime()));
mSentImage.setVisibility(View.INVISIBLE);
}else {
messageText.setVisibility(View.INVISIBLE);
Picasso.with(mSentImage.getContext()).load(message.getMessage()).into(mSentImage);
}