Image fade-in does not save final alpha

I have an image that disappears as soon as the page loads. However, the final alpha of the image set in the animation is not saved. I have the following (simple) xml for my image:

<ImageView android:id="@+id/myImage" android:layout_width="match_parent" android:layout_height="match_parent" android:cropToPadding="true" android:scaleType="centerCrop" android:background="#ffffff" /> 

Then I have an animation file that disappears in the image:

  <set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:fromAlpha="0.0" android:toAlpha="0.6" android:duration="2000"/> </set> 

Then, finally, the code that loads the image:

  body =(ImageView)findViewById(R.id.myImage); body.setBackgroundDrawable(new BitmapDrawable(this.getResources(), background)); Animation myFadeInAnimation = AnimationUtils.loadAnimation(this, R.anim.fadein_bg); body.startAnimation(myFadeInAnimation); 

So, how can I get the latest alpha image to stay after the animation is complete?

thanks

+4
source share
3 answers

It looks like I used body.setBackgroundDrawable () instead of body.setImageDrawable (). Of course, I still need to add setAlpha () there.

+1
source

Try adding a call to the .setFillAfter() method before starting the animation as follows:

 myFadeInAnimation.setFillAfter(true); body.startAnimation(myFadeInAnimation); 
+4
source

When you set the background highlight, try setting the alpha to ImageView setAlpha(float) , which should preserve the alpha value that you end up animating.

+1
source

Source: https://habr.com/ru/post/1393669/


All Articles