您的位置:首页 > 移动开发 > Android开发

android--(动画1_动画补间动画和帧动画)

2015-10-31 12:11 671 查看












//透明方式
//代码方式
Animation alphaAnimation = new AlphaAnimation(0.0f,1.0f);

//
//
//        //加载 动画资源文件
//        Animation animation = AnimationUtils.loadAnimation(this, R.anim.alpha_anim);
//
//        ImageView iv = (ImageView) view;
//
//        //启动动画
//        iv.startAnimation(animation);

aplha_ain.xml:
<alpha
android:duration="3000"
android:fromAlpha="1.0"
android:toAlpha="0.0"/>


//scale 缩放方式
public void click(View view) {

Animation animation = AnimationUtils.loadAnimation(this, R.anim.scale_anim);

ImageView iv = (ImageView) view;

iv.startAnimation(animation);
}

//scale_anim.xml
<scale
android:duration="3000"
android:fillAfter="false"

android:fromXScale="0.0"
android:fromYScale="0.0"

android:pivotX="50%"
android:pivotY="50%"

android:toXScale="1.0"
android:toYScale="1.0"

/>


//平移方式
public void click(View view) {
Animation animation = AnimationUtils.loadAnimation(this, R.anim.translate_anim);

ImageView iv = (ImageView) view;

iv.startAnimation(animation);
}
<translate

android:duration="3000"
android:fromXDelta="0"

android:fromYDelta="0"

android:toXDelta="300" //移动的像素
android:toYDelta="300"

/>


//旋转的方式
public void click(View view) {

Animation animation = AnimationUtils.loadAnimation(this, R.anim.rotate_anim);

ImageView iv = (ImageView) view;

iv.startAnimation(animation);
}

<rotate

android:duration="3000"

android:fromDegrees="0"

android:pivotX="50%"

android:pivotY="50%"
android:toDegrees="360" //正数,则正转,负数,逆转
/>


//帧动画
public void click(View view) {

AnimationDrawable ad = (AnimationDrawable) imageView.getDrawable();

ad.start();//启动

//ad.stop();停止
}

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="true">//为true表示循环一次

<item
android:drawable="@mipmap/a"
android:duration="3000"/>//多长时间播放下一个
<item
android:drawable="@mipmap/b"
android:duration="3000"/>
<item
android:drawable="@mipmap/c"
android:duration="3000"/>

</animation-list>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: