0

I've searched this up many times, but couldn't find an answer which worked for me. So basically, my issue is that I get an image from a backend provider and should display it in the ImageView with an opacity gradient of 100% at the bottom and 0% at the top so the image behind it slowly shows up. Applying a transparent gradient overlay doesn't work since the pixels to be transparent are the actual image I get from the backend service. Any help or ideas would be appreciated! The UI is in XML not Compose

This is the xml for the view I want to add an opacity gradient to. The image comes as a bitmap variable I assign to it's background currently:

<ImageView
    android:id="@+id/bottom_container_background"
    android:layout_width="match_parent"
    android:layout_height="@dimen/bottom_container_height"
    android:adjustViewBounds="true"
    android:alpha="0.7"
    android:src="@drawable/cardview_gradient_shape"
    app:layout_constraintBottom_toBottomOf="@+id/iv_epg"
    app:layout_constraintEnd_toEndOf="@+id/iv_epg"
    app:layout_constraintStart_toStartOf="@+id/iv_epg"
    tools:src="@drawable/cardview_gradient_shape" />
    

val croppedBlurredThumbnail = BitmapDrawable(thumbnailBottomBackgroundBlurred) 

cardLayout.bottom_container_background.background = croppedBlurredThumbnail

eldroid
  • 1
  • 2
  • Why do not you try alpha animation like in this question? https://stackoverflow.com/q/20628973/15805169 – Barney Stinson Aug 22 '22 at 10:46
  • Because it's for a lot of cardviews and shouldn't be an animation, it should be static – eldroid Aug 22 '22 at 12:00
  • Sharing XML code and backend response might be a good idea. – alpertign Aug 22 '22 at 20:09
  • I shared the XML for the view, the backend response doesn't really matter here because I take it as a bitmap variable and then assign it to the view. – eldroid Aug 23 '22 at 08:09
  • As I understand, if you want to set the gradient on the ImageView then, I think you should try this android:foreground="@drawable/cardview_gradient_shape" in ImageView or Wrap ImageView with some layout and then try the same property. – Aditya Nandardhane Aug 23 '22 at 09:10

0 Answers0