android 简单图片动画播放实现

来源:互联网 发布:燕十八知乎 编辑:程序博客网 时间:2024/04/19 04:38

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();