Android的 - 使用阿尔法的动画渐变闪烁的图像 [英] Android - Blinking image using the Alpha fade animation

查看:382
本文介绍了Android的 - 使用阿尔法的动画渐变闪烁的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直挣扎在这几天,最后就决定要问。它是如此简单我得失去了一些东西很基本的。

我有一个定义图像的XML页面布局。我有两个阿尼姆XML页面,一个,以改变的α从0到1,而另一个从1到0,以建立一个闪烁效果。因此,alphaAnimation在XML定义的,我只需要调用它。

图片弹出,但没有循环闪烁效果。

 公共类闪光灯延伸活动{

   //创建动画的名字
动画myFadeInAnimation;
动画myFadeOutAnimation;

/ **第一次创建活动时调用。 * /
@覆盖
公共无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.scanning_view);

 //抢的ImageView和加载动画
    ImageView的myImageView =(ImageView的)findViewById(R.id.blinkingView01);
    动画myFadeInAnimation = AnimationUtils.loadAnimation(空,R.anim.fade_in);
    动画myFadeOutAnimation = AnimationUtils.loadAnimation(空,R.anim.fade_out);

//褪色它和淡入出来。
    myImageView.startAnimation(myFadeInAnimation);
    myImageView.startAnimation(myFadeOutAnimation);
     }
}
 

在动画资源两个XML动画布局:

 < XML版本=1.0编码=UTF-8&GT?;
<设置的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
    <阿尔法机器人:fromAlpha =0.0
    机器人:toAlpha =1.0
    机器人:插=@机器人:动画/ accelerate_interpolator
    机器人:时间=50安卓的repeatCount =无限/>
 < /集>
 

和其他的:

 < XML版本=1.0编码=UTF-8&GT?;
 <设置的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
    <阿尔法机器人:fromAlpha =1.0的Andr​​oid版本:toAlpha =0.0
    机器人:插=@机器人:动画/ accelerate_interpolator
    机器人:时间=1000安卓的repeatCount =无限/>
< /集>
 

解决方案

为什么不使用安卓REPEATMODE =反向

I've been struggling for a few days on this, finally just decided to ask. It's so simple I've got to be missing something very basic.

I have an XML layout page with an image defined. I have two anim XML pages, one to change alpha from 0 to 1, and the other from 1 to 0 in order to create a "blinking" effect. So the alphaAnimation is defined in XML, I just need to call it.

The image pops up, but there's no looping blinking effect.

public class blinker extends Activity {

   //create name of animation
Animation myFadeInAnimation;
Animation myFadeOutAnimation;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.scanning_view);

 //grab the imageview and load the animations
    ImageView myImageView = (ImageView) findViewById(R.id.blinkingView01); 
    Animation myFadeInAnimation = AnimationUtils.loadAnimation(null, R.anim.fade_in);
    Animation myFadeOutAnimation = AnimationUtils.loadAnimation(null, R.anim.fade_out);

//fade it in, and fade it out. 
    myImageView.startAnimation(myFadeInAnimation);
    myImageView.startAnimation(myFadeOutAnimation);
     }
}   

Two XML Animation layouts in Anim resource:

<?xml version="1.0" encoding="UTF-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <alpha android:fromAlpha="0.0" 
    android:toAlpha="1.0" 
    android:interpolator="@android:anim/accelerate_interpolator"  
    android:duration="50" android:repeatCount="infinite"/> 
 </set> 

And the other:

 <?xml version="1.0" encoding="UTF-8"?>
 <set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <alpha android:fromAlpha="1.0" android:toAlpha="0.0" 
    android:interpolator="@android:anim/accelerate_interpolator"  
    android:duration="1000" android:repeatCount="infinite"/> 
</set>

解决方案

Why not use android:repeatMode="reverse"

这篇关于Android的 - 使用阿尔法的动画渐变闪烁的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆