欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

android 简单图片动画播放的实例代码

程序员文章站 2023-12-01 20:24:52
xml中:复制代码 代码如下:       

xml中:

复制代码 代码如下:

        <imageview
            android:id="@+id/touchview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignparentleft="true"
            android:layout_centervertical="true"
            android:src="@drawable/touch" />

java中:
复制代码 代码如下:

               mtouchview = (imageview) findviewbyid(r.id.touchview);
                alphaanimation malphaanimation = new alphaanimation(0.1f, 1.0f); ////创建一个alphaanimation对象,参数从透明到不透明

malphaanimation.setduration(1000);// 设定动画时间
malphaanimation.setrepeatcount(animation.infinite);//定义动画重复时间
malphaanimation.setrepeatmode(animation.reverse);//通过设置重复时间定义动画的行为
mtouchview.setanimation(malphaanimation);
malphaanimation.start();