Android animation 示例
程序员文章站
2022-02-13 20:08:25
...
private void addAnimation(String name) {
array.add(name);
if (name.equals("alpha")) {
anim = new AlphaAnimation(0f, 1.0f);
anim.setDuration(time);
anim.setFillAfter(true);
anims.add(anim);
anim = new AlphaAnimation(1f, 0f);
anim.setDuration(time);
anim.setFillAfter(false);
exit_anims.add(anim);
} else if (name.equals("rotate")) {
anim = new RotateAnimation(0.0f, 360.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
anim.setDuration(time);
anim.setFillAfter(true);
anims.add(anim);
anim = new RotateAnimation(0.0f, -360.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
anim.setDuration(time);
anim.setFillAfter(false);
exit_anims.add(anim);
} else if (name.equals("translate")) {
anim = new TranslateAnimation(width, 0f, 0, 0);
anim.setDuration(time);
anim.setFillAfter(true);
anims.add(anim);
anim = new TranslateAnimation(0, -width, 0, 0);
anim.setDuration(time);
anim.setFillAfter(false);
exit_anims.add(anim);
} else if (name.equals("scale")) {
anim = new ScaleAnimation(0.0f, 1.0f, 1f, 1f, Animation.RELATIVE_TO_PARENT, 0.5f,
Animation.RELATIVE_TO_PARENT, 0.5f);
anim.setDuration(time);
anim.setFillAfter(true);
anim.setStartOffset(200);
anims.add(anim);
anim = new ScaleAnimation(1.0f, 0.0f, 1f, 1f, Animation.RELATIVE_TO_PARENT, 0.5f,
Animation.RELATIVE_TO_PARENT, 0.5f);
anim.setDuration(time);
anim.setFillAfter(false);
anim.setStartOffset(200);
exit_anims.add(anim);
} else {
myView1.setBackgroundResource(R.drawable.widget_animate);
frameAnimation = (AnimationDrawable) myView1.getBackground();
}
}
private void startAnimation(int pos) {
position = pos;
if (position >= 4) {
myView1.setVisibility(View.VISIBLE);
frameAnimation.start();
} else {
myView.setVisibility(View.VISIBLE);
myView.startAnimation(anims.get(pos));
}
}
上一篇: android动画基础
推荐阅读
-
解析AngularJS 作用域及使用示例代码
-
MySQL FEDERATED引擎使用示例, 类似Oracle DBLINK.
-
sql时间格式化输出、Convert函数应用示例
-
高通方案的Android设备几种开机模式的进入与退出
-
jquery常用特效方法使用示例
-
Python WebSocket长连接心跳与短连接的示例
-
Failed to resolve: com.android.support:support-annotations
-
Python实现的递归神经网络简单示例
-
浅谈Android注解在日常开发中的简单使用
-
PHP开发框架Yii Framework教程(31) Zii组件-DetailView示例