обработка позиции просмотра изображения в чате - PullRequest
0 голосов
/ 26 апреля 2019

В моем приложении, когда пользователь отправляет или получает изображения, если пользователь прокручивает от этого изображения и прокручивает назад к нему, изображение становится невидимым, оставляя его последнюю позицию пустой, тем самым портя представление. изображение появляется снова, когда пользователь закрывает 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);
   }
...