Android 补间动画
来源:互联网 发布:江湖家居门户系统源码 编辑:程序博客网 时间:2024/05/16 15:43
public class MainActivity extends AppCompatActivity { private ImageView iv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //这个控件用来执行动画 iv = (ImageView) findViewById(R.id.iv); iv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getApplicationContext(), "你点不到我", Toast.LENGTH_SHORT).show(); } }); } // 点击按钮 实现透明效果 public void click1(View v){ // 创建透明动画 1.0意味着完全不透明 0.0意味着完全透明 AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.0f); alphaAnimation.setDuration(2000); // 设置动画执行的时间 alphaAnimation.setRepeatCount(1); // 设置动画重复的次数 alphaAnimation.setRepeatMode(Animation.REVERSE); // 设置重复的模式 // 开始执行动画 iv.startAnimation(alphaAnimation); } // 点击按钮 实现旋转效果 public void click2(View v) { //fromDegrees 开始角度 toDegrees 结束角度// RotateAnimation rotateAnimation = new RotateAnimation(0, 360); RotateAnimation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); rotateAnimation.setDuration(2000); // 设置动画执行的时间 rotateAnimation.setRepeatCount(1); // 设置动画重复的次数 rotateAnimation.setRepeatMode(Animation.REVERSE); // 设置重复的模式 // 开始执行动画 iv.startAnimation(rotateAnimation); } // 点击按钮 实现缩放效果 public void click3(View v) { ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, 2.0f, 1.0f, 2.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); scaleAnimation.setDuration(2000); // 设置动画执行的时间 scaleAnimation.setRepeatCount(1); // 设置动画重复的次数 scaleAnimation.setRepeatMode(Animation.REVERSE); // 设置重复的模式 // 开始执行动画 iv.startAnimation(scaleAnimation); } // 点击按钮 实现平移效果 但按钮真实的位置还在原位没动 public void click4(View v) { TranslateAnimation translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 0.2f); translateAnimation.setDuration(2000); // 设置动画执行的时间 translateAnimation.setFillAfter(true); // 当动画结束后,停留在结束的位置上 // 开始执行动画 iv.startAnimation(translateAnimation); } // 点击按钮 让动画一起执行 public void click5(View v) { // 从创建动画的合集 AnimationSet set = new AnimationSet(true); AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.0f); alphaAnimation.setDuration(2000); // 设置动画执行的时间 alphaAnimation.setRepeatCount(1); // 设置动画重复的次数 alphaAnimation.setRepeatMode(Animation.REVERSE); // 设置重复的模式 RotateAnimation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); rotateAnimation.setDuration(2000); // 设置动画执行的时间 rotateAnimation.setRepeatCount(1); // 设置动画重复的次数 rotateAnimation.setRepeatMode(Animation.REVERSE); // 设置重复的模式 ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, 2.0f, 1.0f, 2.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); scaleAnimation.setDuration(2000); // 设置动画执行的时间 scaleAnimation.setRepeatCount(1); // 设置动画重复的次数 scaleAnimation.setRepeatMode(Animation.REVERSE); // 设置重复的模式 TranslateAnimation translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 0.2f); translateAnimation.setDuration(2000); // 设置动画执行的时间 translateAnimation.setFillAfter(true); // 当动画结束后,停留在结束的位置上 // 添加动画 set.addAnimation(alphaAnimation); set.addAnimation(rotateAnimation); set.addAnimation(scaleAnimation); set.addAnimation(translateAnimation); // 执行动画 iv.startAnimation(set); }}
0 0
- Android-补间动画
- Android-补间动画
- Android 补间动画
- Android补间动画
- Android 补间动画
- Android 补间动画
- Android 补间动画
- Android补间动画
- Android补间动画
- android 补间动画
- Android 补间动画
- Android补间动画
- Android 动画-----补间动画
- Android动画--补间动画
- android动画 -- 帧动画 补间动画
- Android动画-帧动画&补间动画
- 2. android补间动画
- android移动补间动画
- 【数据结构】--几道栈和队列面试题
- [实训]解决eclipse中复制新项目改名后重新部署项目名不变的问题
- 【京东商城首页实战12】右侧:“京东快报”和“生活服务”
- fragment 收不到 result startActivityForResult 没有返回结果
- 指针的指针的本质
- Android 补间动画
- Python模块常用的几种安装方式
- Myeclipse中出现"A Java Exception has occurred"的弹出提示信息解决方案
- rtsp协议详解
- R3进程DLL注入HOOK
- Python leetcode #3 Longest Substring Without Repeating Characters
- CodeForces
- LeetCode刷题(C++)——3Sum(Medium)
- 第一篇:欢迎使用CSDN-markdown编辑器