Shimmer not showing on shapeable imageview

119 views Asked by At

I have used shapeable image view in my application. I want to load shimmer as a place holder till the image loads in shapeable image view. But the shimmer is not loading. It just shows blank image view until image loads.

<com.google.android.material.imageview.ShapeableImageView
                android:id="@+id/style_img"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:adjustViewBounds="true"
                android:contentDescription="@string/rapturous"
                android:scaleType="centerCrop"
                app:shapeAppearanceOverlay="@style/roundedCornersImageView" />
val shimmer = Shimmer.AlphaHighlightBuilder()
            .setDuration(1800)
            .setBaseAlpha(0.7f)
            .setHighlightAlpha(0.6f)
            .setDirection(Shimmer.Direction.LEFT_TO_RIGHT)
            .setAutoStart(true)
            .build()

        val shimmerDrawable = ShimmerDrawable().apply {
            setShimmer(shimmer)
        }

        Glide.with(context).load(imageUrl).placeholder(shimmerDrawable).into(style_img)

I have tried using simple image view instead of shapeable image view and it works fine. But I want my image view to have rounded corners. I am using implementation 'com.facebook.shimmer:shimmer:0.5.0' library for shimmer

1

There are 1 answers

0
Alvaro Ramirez Crisostomo On BEST ANSWER

It is probably because of the shapeAppearanceOverlay that affects the placeholder, another option would also be to use a normal ImageView, since you mentioned that it works there, and put this ImageView inside a CardView or MaterialCardView, so with it now you are allow to define rounded corners, also if you don't want border define change it to 0

<com.google.android.material.card.MaterialCardView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:strokeWidth="0dp">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:src="@tools:sample/avatars" />

</com.google.android.material.card.MaterialCardView>