From e29ca1256f24635f144b0d87202e1d0f6da0d165 Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Mon, 12 Oct 2020 17:53:31 +0200 Subject: [PATCH] Better align scaled image to message bubbles Fixes images not aligned to the same side as message bubbles in following scenarios: - The image measures are not known before loading it - The information header (sender name + date) is wider than the image Change-Id: Id178905e39cfd1b3353946e920e9523c32867851 --- .../detail/timeline/item/MessageImageVideoItem.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageImageVideoItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageImageVideoItem.kt index 1fb5726ccc..3e731426e8 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageImageVideoItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageImageVideoItem.kt @@ -21,6 +21,7 @@ import android.view.View import android.view.ViewGroup import android.widget.ImageView import android.widget.ProgressBar +import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.view.ViewCompat import androidx.core.view.isVisible import com.airbnb.epoxy.EpoxyAttribute @@ -95,6 +96,18 @@ abstract class MessageImageVideoItem : AbsMessageItem width of the ImageView not adapted to the actual content + // -> Align image within ImageView to same side as message bubbles + holder.imageView.scaleType = if (reverseBubble) ImageView.ScaleType.FIT_END else ImageView.ScaleType.FIT_START + // Case: Message information (sender name + date) makes the containing view wider than the ImageView + // -> Align ImageView within its parent to the same side as message bubbles + (holder.imageView.layoutParams as ConstraintLayout.LayoutParams).horizontalBias = if (reverseBubble) 1f else 0f + } + + class Holder : AbsMessageItem.Holder(STUB_ID) { val progressLayout by bind(R.id.messageMediaUploadProgressLayout) val imageView by bind(R.id.messageThumbnailView)