java - 处理聊天活动中的图像视图位置
问题描述
在我的应用程序中,当用户发送或接收图像时,如果用户滚动离开该图像并滚动回该图像,则图像变得不可见,使其最后一个位置为空,从而弄乱了视图。当用户关闭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);
}
解决方案
推荐阅读
- android - 如何在任何操作上保持活动状态(主页按下、后按、概览按下)
- android - Android 上的倒角进度条
- c# - 将 WPF DataGrid 与 Reactivui 一起使用
- javascript - 使用javascript添加到页面的url
- angular - Angular rxjs:保持活动订阅处理http错误
- c - Pthreads 堆栈优先级
- notifications - 低功耗蓝牙 (BLE) GATT 配置文件中的连接和通知
- linux - 重新格式化 ini 字符串
- python - 张量板 - 错误:已启用跟踪 - 如何解决?
- google-chrome-extension - 我应该请求什么权限才能在特定网站列表上显示模式并有短暂的批准延迟