Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to overlay an icon on a picture

I'm creating an application where the user is allowed to upload pictures. When the picture has been uploaded successfully I would like to add a green check at the upper right corner (drawable). The same when failed but with a cross. Atm I'm using Glide to show URI's on the screen. How could I achieve this?

like image 200
axeldion Avatar asked Sep 20 '25 09:09

axeldion


1 Answers

You can achieve this by calling glide listeners. First you have to add overlay ImageView in layout file with android:visibility="gone".

For example: Layout.xml file

<RelativeLayout
    android:layout_width="200dp"
    android:layout_height="200dp">
    
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:contentDescription="Your main image view"
        android:src="@drawable/gradient_background"/>
    
    <ImageView
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:id="@+id/ivIcon"
        android:contentDescription="Icon to be displayed after result"
        android:src="@drawable/ic_thumb"
        android:layout_margin="10dp"
        android:layout_alignParentEnd="true"
        android:visibility="gone"/>
    
</RelativeLayout>

Then use glide like this

 Glide.with(getActivity())
            .load(RESOURCE_ID)
            .listener(new RequestListener<Drawable>() {
                @Override
                public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
                    ivIcon.setImageResource(faliureImageResourceID);
                    ivIcon.setVisibility(View.VISIBLE);
                    return false;
                }

                @Override
                public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
                    ivIcon.setImageResource(successImageID);
                    ivIcon.setVisibility(View.VISIBLE);  
                    return false;
                }
            })
            .into(mainImageView);

Hope this will work for you.

like image 64
Umer Farooq Avatar answered Sep 23 '25 00:09

Umer Farooq