I've got animation:
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/linear_interpolator"> <alpha android:fromAlpha="0.2" android:toAlpha="1.0" android:duration="500"/> </set>
and ImageView
:
<ImageView android:id="@+id/listViewIcon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/settings" android:alpha="0.2"/>
and code:
final Animation anim = AnimationUtils.loadAnimation(this, R.anim.alpha); final ImageView iv = (ImageView) findViewById(R.id.listViewIcon); anim .setFillAfter(true); iv.startAnimation(anim);
So at the beginning I have ImageView
with alpha 0.2
and at the end I want to have ImageView
with alpha 1
. But it doesn't work like that - when animation starts more alpha is added and animation finish with alpha 0.2
What do I have to change to animate my image from 0.2
up to 1
?
I've checked with different settings - I set android:alpha="1.0"
, fromAlpa="1.0"
, toAlpha="0.2"
it works like I expected - from alpha 1
to 0.2
. It looks like alpha from ImageView
is multiplied by alpha from animation...
An animation that controls the alpha level of an object. Useful for fading things in and out. This animation ends up changing the alpha property of a Transformation.
"alpha" is used to specify the opacity for an image. set alpha using XML attribute: android:alpha="0.5" Note: takes float value from 0 (transparent) to 1 (fully visible)
On Android 4.4 (API level 19) and higher, you can use the transition framework to create animations when you swap the layout within the current activity or fragment. All you need to do is specify the starting and ending layout, and what type of animation you want to use.
The easiest way to animate Visibility changes is use Transition API which available in support (androidx) package. Just call TransitionManager. beginDelayedTransition method then change visibility of the view. There are several default transitions like Fade , Slide .
Try this
AlphaAnimation animation1 = new AlphaAnimation(0.2f, 1.0f); animation1.setDuration(1000); animation1.setStartOffset(5000); animation1.setFillAfter(true); iv.startAnimation(animation1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With