Search code examples
androidkotlinandroid-layoutandroid-imageviewandroid-glide

Why ImageView not showing the string image url using Glide library?


I have a problem with Glide not showing image URL in ImageView.

I suppose to get the image URL and fit it inside ImageView of a RecyclerView item, the it was working fine first, but after some changes it's not showing and i don't know where is the problem

If anyone can help me to find the error.

<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:id="@+id/sentContent"
android:gravity="end"
android:clickable="true"
android:paddingTop="10dp"
android:paddingBottom="10dp"
xmlns:app="http://schemas.android.com/apk/res-auto">

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:id="@+id/sentTxtMsgL"
    android:clickable="true"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/sentMsgL"
        android:background="@drawable/sent_bg"
        android:clickable="true"
        android:paddingStart="15dp"
        android:paddingEnd="18dp"
        android:paddingTop="5dp"
        android:paddingBottom="5dp"
        android:minWidth="150dp"
        android:minHeight="40dp">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/msgViewLS"
            android:orientation="horizontal"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/sentMsg"
                android:maxWidth="250dp"
                android:text=""
                android:textColor="@color/black"
                android:textSize="16sp"
                android:textStyle="normal"
                android:layout_marginStart="22dp"
                android:layout_marginEnd="8dp"
                android:layout_marginTop="5dp"
                android:layout_marginBottom="5dp"/>

        </LinearLayout>

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/timeSeenL"
            android:orientation="horizontal"
            app:layout_constraintTop_toBottomOf="@id/msgViewLS"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent">

            <ImageView
                android:layout_width="20dp"
                android:layout_height="15dp"
                android:id="@+id/sentMarkS"
                android:src="@drawable/sent_n"
                android:contentDescription="@string/todo"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintBottom_toBottomOf="parent" />

            <ImageView
                android:layout_width="20dp"
                android:layout_height="15dp"
                android:id="@+id/sentRMarkS"
                android:src="@drawable/sent_r"
                android:visibility="gone"
                android:contentDescription="@string/todo"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintBottom_toBottomOf="parent" />

            <ImageView
                android:layout_width="20dp"
                android:layout_height="15dp"
                android:id="@+id/seenMarkS"
                android:src="@drawable/seen_l"
                android:visibility="gone"
                android:contentDescription="@string/todo"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintBottom_toBottomOf="parent" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/dateTimeTxtS"
                android:text="@string/todo"
                android:layout_marginEnd="25dp"
                android:layout_marginTop="3dp"
                android:textSize="12sp"
                android:textColor="@color/gray"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent" />

        </androidx.constraintlayout.widget.ConstraintLayout>

    </androidx.constraintlayout.widget.ConstraintLayout>

</LinearLayout>

<LinearLayout
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:id="@+id/sentImgL"
    android:layout_margin="3dp"
    android:padding="6dp"
    android:gravity="center"
    android:maxWidth="200dp"
    android:orientation="vertical"
    android:background="@drawable/sent_img_bg"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintEnd_toEndOf="parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/sentImgLL"
        android:layout_marginEnd="8dp"
        android:background="?selectableItemBackground"
        android:clickable="true">

        <androidx.cardview.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/receivedImgCard"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="5dp"
            app:cardCornerRadius="18dp">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/sentImg"
                android:src="@drawable/me_p"
                android:adjustViewBounds="true"
                android:scaleType="fitXY"
                android:layout_gravity="center"
                android:cropToPadding="true"
                android:contentDescription="@string/todo" />

        </androidx.cardview.widget.CardView>

    </LinearLayout>

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/dateTimeImgLS"
        android:layout_margin="3dp"
        android:orientation="horizontal">

        <ImageView
            android:layout_width="20dp"
            android:layout_height="15dp"
            android:id="@+id/receivedIMarkS"
            android:src="@drawable/sent_n"
            android:contentDescription="@string/todo"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent" />

        <ImageView
            android:layout_width="20dp"
            android:layout_height="15dp"
            android:id="@+id/sentIRMarkS"
            android:src="@drawable/sent_r"
            android:visibility="gone"
            android:contentDescription="@string/todo"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent" />

        <ImageView
            android:layout_width="20dp"
            android:layout_height="15dp"
            android:id="@+id/seenIMarkS"
            android:src="@drawable/seen_l"
            android:visibility="gone"
            android:contentDescription="@string/todo"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/dateITimeTxtS"
            android:text="@string/todo"
            android:layout_marginStart="5dp"
            android:layout_marginTop="3dp"
            android:textSize="12sp"
            android:textColor="@color/gray"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toEndOf="@id/receivedIMarkS" />

    </androidx.constraintlayout.widget.ConstraintLayout>

</LinearLayout>

<androidx.cardview.widget.CardView
    android:id="@+id/emojiSentAttach"
    android:layout_width="350dp"
    android:layout_height="60dp"
    android:layout_gravity="bottom"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:visibility="gone"
    android:elevation="1dp"
    android:translationZ="0dp"
    app:cardBackgroundColor="#FFFFFF"
    app:cardCornerRadius="20dp"
    app:cardElevation="2dp"
    app:cardPreventCornerOverlap="false"
    app:cardUseCompatPadding="true"
    app:contentPadding="0dp"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintEnd_toEndOf="parent">

    <LinearLayout
        android:id="@+id/sentEmoL"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical">

    </LinearLayout>

</androidx.cardview.widget.CardView>

</androidx.constraintlayout.widget.ConstraintLayout>

if (currentMsg.type == "photo"){
            viewHolder.binding.sentImgL.visibility = View.VISIBLE
            viewHolder.binding.sentTxtMsgL.visibility = View.GONE
            //holder.binding.sentImg.setImageURI(currentMsg.urlImg?.toUri())
            Glide.with(holder.itemView.context).load(currentMsg.message).into(holder.binding.sentImg)
        }

Solution

  • You can increase the size of ImageView and verify with below xml code. Please also check if you are using valid image url to load from glide and handle exceptions found while loading image from glide and print in stack trace.

    <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/sentContent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="end"
        android:clickable="true"
        android:gravity="end"
        android:paddingTop="10dp"
        android:paddingBottom="10dp">
    
        <LinearLayout
            android:id="@+id/sentTxtMsgL"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:orientation="horizontal"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent">
    
            <androidx.constraintlayout.widget.ConstraintLayout
                android:id="@+id/sentMsgL"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/sent_bg"
                android:clickable="true"
                android:minWidth="150dp"
                android:minHeight="40dp"
                android:paddingStart="15dp"
                android:paddingTop="5dp"
                android:paddingEnd="18dp"
                android:paddingBottom="5dp">
    
                <LinearLayout
                    android:id="@+id/msgViewLS"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent">
    
                    <TextView
                        android:id="@+id/sentMsg"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="22dp"
                        android:layout_marginTop="5dp"
                        android:layout_marginEnd="8dp"
                        android:layout_marginBottom="5dp"
                        android:maxWidth="250dp"
                        android:text=""
                        android:textColor="@color/black"
                        android:textSize="16sp"
                        android:textStyle="normal" />
    
                </LinearLayout>
    
                <androidx.constraintlayout.widget.ConstraintLayout
                    android:id="@+id/timeSeenL"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintTop_toBottomOf="@id/msgViewLS">
    
                    <ImageView
                        android:id="@+id/sentMarkS"
                        android:layout_width="20dp"
                        android:layout_height="15dp"
                        android:contentDescription="@string/todo"
                        android:src="@drawable/sent_n"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintTop_toTopOf="parent" />
    
                    <ImageView
                        android:id="@+id/sentRMarkS"
                        android:layout_width="20dp"
                        android:layout_height="15dp"
                        android:contentDescription="@string/todo"
                        android:src="@drawable/sent_r"
                        android:visibility="gone"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintTop_toTopOf="parent" />
    
                    <ImageView
                        android:id="@+id/seenMarkS"
                        android:layout_width="20dp"
                        android:layout_height="15dp"
                        android:contentDescription="@string/todo"
                        android:src="@drawable/seen_l"
                        android:visibility="gone"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintTop_toTopOf="parent" />
    
                    <TextView
                        android:id="@+id/dateTimeTxtS"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="3dp"
                        android:layout_marginEnd="25dp"
                        android:text="@string/todo"
                        android:textColor="@color/gray"
                        android:textSize="12sp"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintTop_toTopOf="parent" />
    
                </androidx.constraintlayout.widget.ConstraintLayout>
    
            </androidx.constraintlayout.widget.ConstraintLayout>
    
        </LinearLayout>
    
        <LinearLayout
            android:id="@+id/sentImgL"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:layout_margin="3dp"
            android:background="@drawable/sent_img_bg"
            android:gravity="center"
            android:maxWidth="200dp"
            android:orientation="vertical"
            android:padding="6dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent">
    
            <LinearLayout
                android:id="@+id/sentImgLL"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginEnd="8dp"
                android:background="?selectableItemBackground"
                android:clickable="true">
    
                <androidx.cardview.widget.CardView
                    android:id="@+id/receivedImgCard"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginStart="5dp"
                    android:layout_marginEnd="8dp"
                    app:cardCornerRadius="18dp">
    
                    <ImageView
                        android:id="@+id/sentImg"
                        android:layout_width="50dp"
                        android:layout_height="50dp"
                        android:layout_gravity="center"
                        android:adjustViewBounds="true"
                        android:contentDescription="@string/todo"
                        android:cropToPadding="true"
                        android:scaleType="fitXY"
                        android:src="@drawable/me_p" />
    
                </androidx.cardview.widget.CardView>
    
            </LinearLayout>
    
            <androidx.constraintlayout.widget.ConstraintLayout
                android:id="@+id/dateTimeImgLS"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="3dp"
                android:orientation="horizontal">
    
                <ImageView
                    android:id="@+id/receivedIMarkS"
                    android:layout_width="20dp"
                    android:layout_height="15dp"
                    android:contentDescription="@string/todo"
                    android:src="@drawable/sent_n"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />
    
                <ImageView
                    android:id="@+id/sentIRMarkS"
                    android:layout_width="20dp"
                    android:layout_height="15dp"
                    android:contentDescription="@string/todo"
                    android:src="@drawable/sent_r"
                    android:visibility="gone"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />
    
                <ImageView
                    android:id="@+id/seenIMarkS"
                    android:layout_width="20dp"
                    android:layout_height="15dp"
                    android:contentDescription="@string/todo"
                    android:src="@drawable/seen_l"
                    android:visibility="gone"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />
    
                <TextView
                    android:id="@+id/dateITimeTxtS"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="5dp"
                    android:layout_marginTop="3dp"
                    android:text="@string/todo"
                    android:textColor="@color/gray"
                    android:textSize="12sp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintStart_toEndOf="@id/receivedIMarkS"
                    app:layout_constraintTop_toTopOf="parent" />
    
            </androidx.constraintlayout.widget.ConstraintLayout>
    
        </LinearLayout>
    
        <androidx.cardview.widget.CardView
            android:id="@+id/emojiSentAttach"
            android:layout_width="350dp"
            android:layout_height="60dp"
            android:layout_gravity="bottom"
            android:layout_marginRight="8dp"
            android:elevation="1dp"
            android:translationZ="0dp"
            android:visibility="gone"
            app:cardBackgroundColor="#FFFFFF"
            app:cardCornerRadius="20dp"
            app:cardElevation="2dp"
            app:cardPreventCornerOverlap="false"
            app:cardUseCompatPadding="true"
            app:contentPadding="0dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent">
    
            <LinearLayout
                android:id="@+id/sentEmoL"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:orientation="vertical">
    
            </LinearLayout>
    
        </androidx.cardview.widget.CardView>
    </androidx.constraintlayout.widget.ConstraintLayout>