In my application, I have a RecyclerView displaying products with an image and a title. The layout use a ConstraintLayout (version 2.0.0-alpha5) and the TextView width is based on the image width. I want the title to be singleLine, so I declared maxLines=1 (I also used the singleLine attribute to see if it was the problem) and I would expect the first word to be displayed, however it is (apparently) randomly showing only the first letter.
This is my layout :
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="4dp">
<androidx.cardview.widget.CardView
android:id="@+id/product_img_card"
android:layout_width="wrap_content"
android:layout_height="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@+id/product_designation">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/product_img_layout"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<ImageView
android:id="@+id/product_img"
android:layout_width="0dp"
android:layout_height="match_parent"
android:scaleType="centerCrop"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="V,1:1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:src="@drawable/img_product_sample"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
<TextView
android:id="@+id/product_designation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:textSize="9sp"
android:fontFamily="sans-serif-smallcaps"
android:background="#FF0"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/product_img_card"
app:layout_constraintStart_toStartOf="@+id/product_img_card"
app:layout_constraintTop_toBottomOf="@+id/product_img_card"
tools:text="COUTEAU PLAT 16CM BOIS"
android:maxLines="1"/>
My RecyclerView adapter onBindViewHolder method is as follow :
override fun onBindViewHolder(holder: ProductHolder, position: Int) {
val product = listProducts[holder.layoutPosition]
holder.designation.text = product.designation
Log.d(
"MyProblem",
"Product.designation=[${product.designation}], textview content=[${holder.designation.text}]"
)
val photo = PhotosUtils.getFirstroductPicture(holder.itemView.context, product.codeArticle)
if (photo != null) {
val uri = Uri.fromFile(photo)
GlideApp.with(holder.img)
.load(uri)
.error(R.drawable.ic_broken_image_black_24dp)
.signature { photo.length().toString() }
.into(holder.img)
} else {
GlideApp.with(holder.img)
.load(R.drawable.ic_broken_image_black_24dp)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
//.signature { System.currentTimeMillis() }
.into(holder.img)
}
}
The picture is correctly displayed, the product.designation and the textview.text value are correct ("JERRICAN PLASTIQUE 5L" for instance) however, some times, I only have the first letter displayed in the TextView. The background color displays a correct width.
In the screenshot below, I firstly see the word entirely of one product, then I scrolled in the RecyclerView and came back to this product who was correctly displayed and it only showed the first letter again.
Any idea on why this is happening?