博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android 动画效果 及 自定义动画
阅读量:6861 次
发布时间:2019-06-26

本文共 2920 字,大约阅读时间需要 9 分钟。

1. View动画-透明动画效果

2. View动画-旋转动画效果
3. View动画-移动动画效果
4. View动画-缩放动画效果
5. View动画-动画效果混合
6. View动画-动画效果侦听
7. 自定义动画效果

工程代码:

-----------------------------------

1. View动画-透明动画效果

Java代码实现

AlphaAnimation aa = new AlphaAnimation(0, 1); //透明动画效果aa.setDuration(1000);v.startAnimation(aa);

XML文件实现

在 res/anim 下创建alpha动画效果文件 alpha_animation.xml

//使用v.startAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.alpha_animation));

 

 

2. View动画-旋转动画效果

3. View动画-移动动画效果

4. View动画-缩放动画效果

5. View动画-动画效果混合

Java实现,透明效果和移动效果结合

public class MixedAnimDemoActivity extends Activity {    private Button mixedBtn;    private AnimationSet as;        @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_mixed_anim_demo);                as = new AnimationSet(true); //是否共用动画补间        as.setDuration(1000);        AlphaAnimation aa = new AlphaAnimation(0, 1);        aa.setDuration(1000);        as.addAnimation(aa);                TranslateAnimation ta = new TranslateAnimation(200, 0, 200, 0);        ta.setDuration(1000);        as.addAnimation(ta);                mixedBtn = (Button)findViewById(R.id.mixedBtn);        mixedBtn.setOnClickListener(new OnClickListener() {            @Override            public void onClick(View v) {                v.startAnimation(as);            }        });    }}

6. View动画-动画效果侦听

创建动画效果的侦听事件, 在动画结束之后弹出一个Toast

AlphaAnimation aa = new AlphaAnimation(0, 1);aa.setDuration(1000);aa.setAnimationListener(new AnimationListener() {        @Override    public void onAnimationStart(Animation animation) {        // TODO Auto-generated method stub    }        @Override    public void onAnimationRepeat(Animation animation) {        // TODO Auto-generated method stub    }        @Override    public void onAnimationEnd(Animation animation) {        // TODO Auto-generated method stub        Toast.makeText(getApplicationContext(), "Animate end", Toast.LENGTH_LONG).show();    }});as.addAnimation(aa);

 

7. 自定义动画效果

需要创建一个CustomAnim动画类,集成 Animation

public class CustomAnim extends Animation {    @Override    public void initialize(int width, int height, int parentWidth,            int parentHeight) {        // w我们需要知道目标动画效果的宽和高,所以需要重写该方法        // 父级容器的宽高        // initialize 在 applyTransformation之前执行        super.initialize(width, height, parentWidth, parentHeight);    }        @Override    protected void applyTransformation(float interpolatedTime, Transformation t) {        // TODO Auto-generated method stub        // interpolatedTime 补间时间, 从0~1, 动画执行完为1        //t.setAlpha(interpolatedTime); //可以实现透明动画                //可以实现移动效果        //t.getMatrix().setTranslate(200 * interpolatedTime, 200 * interpolatedTime);                //左右摇摆效果        t.getMatrix().setTranslate((float)(Math.sin(interpolatedTime*50)*10), 0);         super.applyTransformation(interpolatedTime, t);    }}

 

工程代码:

 

转载地址:http://rnqyl.baihongyu.com/

你可能感兴趣的文章
学习extjs的布局
查看>>
java-swing模拟实现时钟效果
查看>>
java points[复习]
查看>>
在另一个线程中无法用((CMainFrame *)AfxGetMainWnd())
查看>>
Ignatius and the Princess IV
查看>>
BC#50 1003 The mook jong
查看>>
DEDECMS中,自增长标签
查看>>
JS学习之动态加载script和style样式
查看>>
python快速入门——进入数据挖掘你该有的基础知识
查看>>
42 windows_42_Thread_WaitableTimer 线程 - 等候线程
查看>>
通过xml将传入的字符串转成表格列值
查看>>
优秀安卓开发周刊推荐——My favorite
查看>>
关于centos6上用yum安装mysql后,出现的ERROR 2002 (HY000)的解决办法
查看>>
当在浏览器中输入一个url后回车,后台发生了什么?比如输入url后,你看到了百度的首页,那么这一切是如何发生的呢?...
查看>>
人事管理系统——数据库操作类
查看>>
Bootstrap
查看>>
uva 1339
查看>>
solr之环境配置一
查看>>
wordpress 系列之 header 导航
查看>>
学习中的问题
查看>>