将图像从不透明动画到半透明(并保持半透明)
我有一个图像,我想慢慢地从不透明褪色到半透明。我主要是通过查看动画资源来实现的:
布局:
<ImageView
android:id="@+id/swipeImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/one_finger_swipe" />
Activity:
ImageView swipeImage = (ImageView) toReturn.findViewById(R.id.swipeImage);
Animation animation = AnimationUtils.loadAnimation(this, R.anim.fadeout);
swipeImage.startAnimation(animation);
res/anim/fadeout.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="true"
android:interpolator="@android:anim/accelerate_interpolator">
<alpha android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="2000"/>
</set>
正如我所说,我基本上已经实现了这一点,因为图像确实会褪色。然而,动画完成后又恢复为不透明。如何让它保持半透明?
I have an image which I want to slowly fade from opaque to translucent. I've mostly achieved it by looking at Animation Resources:
layout:
<ImageView
android:id="@+id/swipeImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/one_finger_swipe" />
Activity:
ImageView swipeImage = (ImageView) toReturn.findViewById(R.id.swipeImage);
Animation animation = AnimationUtils.loadAnimation(this, R.anim.fadeout);
swipeImage.startAnimation(animation);
res/anim/fadeout.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="true"
android:interpolator="@android:anim/accelerate_interpolator">
<alpha android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="2000"/>
</set>
As I said, I've mostly achieved this because the image does indeed fade. However after the Animation is complete is returns to being opaque. How do I make it stay translucent?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
需要调用
animation.setFillAfter(true)
android:fillAfter
也可以在XML中使用。You need to call
animation.setFillAfter(true)
android:fillAfter
can also be used in XML.