动画分类:
View Animation
补间动画 Tween Animation
帧动画 Frame Animation
Property Animation(3.0)
1.补间动画Tween
alpha(透明度)
rotate(旋转) scale(缩放) translate(移动)
2.动画监听
AnimationListener
3.帧动画
Frame
alpha:透明度
实现效果:
alpha属性:
android:fromAlpha="" (透明度开始值)
android:toAlpha=""(透明度结束值)
android:duration=""(执行时长 值:毫秒)
android:fillAfter="" (保留动画结束之后的状态 值:true or false)
在文件夹res下新建一个文件夹anim新建一个xml文件如下:
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="1.0"
android:toAlpha="0.2"
android:duration="1000"
android:fillAfter="true"></alpha>
代码实现:
package com.example.g160628_android_17_animation;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
private ImageView imageView;
private Button alpha;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = (ImageView) findViewById(R.id.main_image);
alpha = (Button) findViewById(R.id.but_main_alpha);
}
public void operation(View view){
//加载动画
Animation animation=AnimationUtils.loadAnimation(this,R.anim.iv_alpha);
//给图片开启动画
imageView.startAnimation(animation);
}
}