Android中的动画

来源:互联网 发布:世界黑客编程大赛 编辑:程序博客网 时间:2024/05/22 14:03

帧动画:Fragent Animation

属性动画:Property Animation

补间动画:Tween Animation

  • 淡入淡出动画:AlphaAnimation

  • 旋转动画:RotateAnimation

  • 伸缩动画 :ScaleAnimation

  • 平移动画:TranslateAnimation

淡入淡出动画:AlphaAnimation

(1)新建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.1"    android:duration="500"    android:repeatCount="infinite"    android:repeatMode="reverse"></alpha>

(2)编写MainActivity

public class MainActivity extends Activity {    private TextView tv;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        tv=(TextView)findViewById(R.id.textView1);    }    public void doClick(View view){        switch (view.getId()) {        case R.id.button4:            //Animation a4 = AnimationUtils.loadAnimation(            //      this, R.anim.translate);            //tv.startAnimation(a4);            //使用代码定义动画效果            Animation a5=new TranslateAnimation(0, 200, 0, 200);            Button b1=(Button)findViewById(R.id.button1);            a5.setDuration(1000);            a5.setFillAfter(true);            b1.startAnimation(a5);            break;        case R.id.button3:            Animation a3 = AnimationUtils.loadAnimation(                    this, R.anim.scale);            tv.startAnimation(a3);            break;        case R.id.button2:            //加载旋转动画的配置文件执行            Animation a2 = AnimationUtils.loadAnimation(                    this, R.anim.rotate);            tv.startAnimation(a2);            break;        case R.id.button1:            //加载淡入淡出动画的配置文件执行            Animation a1 = AnimationUtils.loadAnimation(                    this, R.anim.alpha);            tv.startAnimation(a1);            break;        }    }    @Override    public boolean onCreateOptionsMenu(Menu menu) {        // Inflate the menu; this adds items to the action bar if it is present.        getMenuInflater().inflate(R.menu.main, menu);        return true;    }}

下载:
http://download.csdn.net/detail/prince77qiqiqq/9628232

0 0
原创粉丝点击