动画主要分三大类:补间动画,帧动画和属性动画
一:补间动画有:渐变动画,位移动画,伸缩动画,旋转动画等
这些动画都是在res文件新建个anim文件,在anim文件下建立xml文件
渐变动画
<?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:duration="3000"
/>
</set>
位移动画
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="3000"
android:fromXDelta="0" android:fromYDelta="0"
android:toXDelta="300" android:toYDelta="300"
/>
</set>
伸缩动画
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:fromXScale="0.0" android:fromYScale="0.0"
android:toXScale="1.0" android:toYScale="1.0"
android:fillAfter="false" android:duration="3000"
android:pivotX="50%" android:pivotY="50%"
/>
</set>
旋转动画
这里写代码片<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<a
android:duration="3000"
android:fromDegrees="0" android:toDegrees="360"
android:pivotX="50%" android:pivotY="50%"
/>
</set>
在Activity中加入这些动画就可以了
public class MainActivity extends Activity {
//android中的动画
/**
* Animations:三种View 补件动画、Drawable 帧动画 Property Animation属性动画
* Tween动画:
* 1.Alpha渐变透明度动画
* 2.scale:渐变尺寸伸缩动画
* 3.Translate:画面转换位置移动动画
* startAnimation启动动画
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
//渐变透明动画
private void AlphaClick(View view){
//Animation animations=new AlphaAnimation(1.0f,0.0f);
//加载动画资源文件
Animation animation = AnimationUtils.loadAnimation(this, R.anim.myalpha);
ImageView iv=(ImageView) view;
iv.startAnimation(animation);
}
//渐变尺寸动画
private void ScaleClick(View view){
Animation animation = AnimationUtils.loadAnimation(this, R.anim.myscale);
ImageView iv=(ImageView) view;
iv.startAnimation(animation);
}
//位移动画
private void translateClick(View view){
Animation animation = AnimationUtils.loadAnimation(this, R.anim.mytranslate);
ImageView iv=(ImageView) view;
iv.startAnimation(animation);
}
//旋转动画
private void rotateClick(View view){
Animation animation = AnimationUtils.loadAnimation(this, R.anim.mytranslate);
ImageView iv=(ImageView) view;
iv.startAnimation(animation);
}
private void TweenClick(View view){
ImageView iv=(ImageView) view;
AnimationDrawable ad= (AnimationDrawable) iv.getDrawable();
ad.start();
//ad.stop();
}
}
《Kotlin语法基础到实战开发》系列课程视频
http://edu.youkuaiyun.com/course/detail/6409?locationNum=7&fps=1&ref=srch&loc=1