动画设置
来源:互联网 发布:淘宝复制链接没有响应 编辑:程序博客网 时间:2024/06/03 21:02
//位移动画
//缩放动画
//旋转动画
//Activity的跳转动画
//位移
public void trans(View view){ //使用代码创建位移的动画....Translate位移 TranslateAnimation translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 1.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 1.0f); //动画要执行需要指定执行的时间 translateAnimation.setDuration(3000); //重复执行动画....设置重复的次数 translateAnimation.setRepeatCount(1); //设置重复执行的模式 /** * Animation.RESTART重新再次执行动画,,,默认就是这种形式 * Animation.REVERSE反过来再次执行动画 * * 重复的模式只在重复次数大于0的时候起作用,,,,或者重复次数设置为 INFINITE * * Animation.INFINITE无限次循环 */ translateAnimation.setRepeatMode(Animation.REVERSE); //开始动画 imageView.startAnimation(translateAnimation); }
//缩放动画
public void scale(View view) { /** * pivotXType, 中心点x轴的类型 * pivotXValue, * pivotYType, * pivotYValue */ ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, 0.0f, 1.0f, 0.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); scaleAnimation.setDuration(3000); //设置动画结束之后保持结束的状态 scaleAnimation.setFillAfter(true); imageView.startAnimation(scaleAnimation); }
//透明度变化
public void ala(View view) { /** * fromAlpha,开始的透明度 * toAlpha,,结束的 */ AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.5f); alphaAnimation.setDuration(3000); imageView.startAnimation(alphaAnimation); }
//旋转动画
/** * fromDegrees, 起始的角度 * toDegrees, 终点的角度 * pivotXType, 中心x轴的类型 * pivotXValue, 中心x轴的值 * pivotYType, * pivotYValue * @param view */ public void rotate(View view) { RotateAnimation rotateAnimation = new RotateAnimation(0, -360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); rotateAnimation.setDuration(3000); imageView.startAnimation(rotateAnimation); }//组合动画
public void zuhe(View view) { TranslateAnimation translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 1.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 1.0f); ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, 0.0f, 1.0f, 0.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.5f); RotateAnimation rotateAnimation = new RotateAnimation(0, -360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); //创建一个组合动画...AnimationSet...shareInterpolator插值器(设置插值器可以是动画产生加速效果) //给组合添加动画 AnimationSet animationSet = new AnimationSet(true);//组合动画是否共同使用一个插值器 animationSet.addAnimation(scaleAnimation); animationSet.addAnimation(alphaAnimation); animationSet.addAnimation(rotateAnimation); //位移动画 animationSet.addAnimation(translateAnimation); //设置时间 animationSet.setDuration(3000); imageView.startAnimation(animationSet); }
//Activity的跳转动画
public void tiaozhuan(View view) { Intent intent = new Intent(MainActivity.this,AecondActivity.class); startActivity(intent); //给跳转加动画 /** *只需要在启动Activity后使用overridePendingTransition方法传入anim的id即可完成Activity的切换动画效果。 * int enterAnim, 进入的动画,,,第二个界面的动画...xml资源文件下的动画的id * int exitAnim,,,第一个界面出去的动画 */ overridePendingTransition(R.anim.anim_in, R.anim.anim_out); //overridePendingTransition(R.anim.trans_in, R.anim.trans_out); }
//在value下创建anim文件anim_in.xml/anim_out.xml
//创建进入和退出的动画
<?xml version="1.0" encoding="utf-8"?><alpha xmlns:android="http://schemas.android.com/apk/res/android" android:duration="3000" android:fromAlpha="0" android:toAlpha="1" ></alpha>
<?xml version="1.0" encoding="utf-8"?><alpha xmlns:android="http://schemas.android.com/apk/res/android" android:duration="3000" android:fromAlpha="1" android:toAlpha="0" ></alpha>
//位移
<?xml version="1.0" encoding="utf-8"?><translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="3000" android:fromXDelta="100%p" android:fromYDelta="0" android:toXDelta="0" android:toYDelta="0" > <!-- 在xml动画文件中没有type这个属性,,,,100%p代表着相对父窗体,,,100%相对自己,,,50.0f数值就是一个绝对的类型 --></translate>
<?xml version="1.0" encoding="utf-8"?><translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="3000" android:fromXDelta="0" android:fromYDelta="0" android:toXDelta="-100%p" android:toYDelta="0" ></translate>
阅读全文
0 0
- 动画设置
- 设置动画
- 动画设置
- css3动画,设置动画基点
- 设置动画效果
- LayoutTransition设置动画
- presentModalViewController设置动画效果
- tabBarItem 设置动画 animation
- Android设置开机动画
- presentModalViewController 设置动画效果
- UIView动画设置
- CSS动画设置
- 设置动画,旋转
- 设置activity切换动画
- 页面动画设置
- 使用ValueAnimator设置动画
- 使用ObjectAnimator设置动画
- Theme中设置动画
- 【Java】基本类型之long(六)
- luogu1200 [USACO1.1]你的飞碟在这儿Your Ride Is Here
- 程序员这样面试,拿到offer的几率是80%
- 程序员,这样面试,你的成功率能达到 90%!
- python文件转为exe文件
- 动画设置
- C#数据类型转换——数值字符串和数值之间的转换
- xlistview刷新加载+Drawlayout+多条目
- Codeforces 898D Alarm Clock (贪心好题)
- 把所有文本文件合成一个文件
- p62 练习3.3 通过只调整指针(而不是数据)来交换两个相邻的元素,使用:
- MVP二级购物车
- 数据库连接池Druid使用总结
- 搭建分布式集群