1

I have to successfully load an image to this imageview and I am using glide. My biggest challenged however is I want this rectangle drawable to be in the image and the image to fit in the white rectangle drawable.

Here is my glide function

private fun loadUrl(url: String) {
     Glide.with(this)
         .asBitmap()
         .load(url)
         .fitCenter()
         .centerInside()
         .into(object : CustomTarget<Bitmap?>() {
             override fun onResourceReady(
                 resource: Bitmap,
                 transition: Transition<in Bitmap?>?
             ) {
                 binding.imageview.setImageBitmap(resource)
                 binding.imageview.setBackgroundResource(R.drawable.white_rectangle)
             }
             override fun onLoadCleared(placeholder: Drawable?) {
             }
         })
 }

My image view

<ImageView
     android:id="@+id/imageview"
     android:layout_width="48dp"
     android:layout_height="48dp"

I want to achieve something like this.

I saw this one how can I advance this?

How to make border for circle cropped image in glide

enter image description here

Suraya
  • 63
  • 7

1 Answers1

0

A little trick is in your XML, to put your ImageView inside another component like a FrameLayout with the background and border you need and with Width and Height with few DPs of difference, as the example below. This way, the image fits in the border:

        <FrameLayout
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_marginStart="10dp"
            android:layout_gravity="center"
            android:background="@drawable/background_image">

            <ImageView
                android:id="@+id/image"
                android:layout_width="37dp"
                android:layout_height="37dp"
                android:layout_gravity="center"
                android:adjustViewBounds="true" />
        </FrameLayout>