星空网 > 软件开发 > 操作系统

安卓第十八天笔记


title:动画

动画

1.补间动画

  1. Animation.ABSOLUTE:用于指定后面的数值是绝对值的像素。
  2. Animation.RELATIVETOSELF: 用于指定后面的数值是自己宽高的倍数
  3. Animation.RELATIVETOPARENT : 用于指定后面的数值是自己的父控件宽高的倍数
  4. Animation.RESTART播放重新回到原点
  5. Animation.REVERSE播放回接着,反向播放

2.平移

fromXType 水平播放的类型fromXValue 从哪开始,0表示现在的位置toXType,  到什么位置的类型toXValue 到什么坐标fromYType 垂直播放的类型fromYValue 从哪开始,0表示现在的位置toYType 到什么位置的类型toYValue 到什么坐标
TranslateAnimation translate = new TranslateAnimation(      Animation.RELATIVE_TO_SELF, -2,       Animation.RELATIVE_TO_SELF, 2,       Animation.RELATIVE_TO_SELF, 0,      Animation.RELATIVE_TO_SELF, 1);  //设置显示时间  translate.setDuration(3000);  //播放资源为无限循环  translate.setRepeatCount(Animation.INFINITE);  //播放模式,反转播放,先顺着播完,就反着播放  translate.setRepeatMode(Animation.REVERSE);  //哪个组件在播放,设置  imageView.setAnimation(translate);  //开始播放  translate.start();

 

3.旋转

/*   * fromDegrees, 从什么角度开始 0 从现在的 toDegrees, 270度 pivotXType, X中心点类型   * Animation.RELATIVE_TO_SELF自身 pivotXValue, 中心点值 0.5表示这个图片的一半置   * pivotYType, Y中心点类型Animation.RELATIVE_TO_SELF自身   * pivotYValue 0.5f   */  RotateAnimation rotate = new RotateAnimation(0, 360,      Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,      3);  //播放显示时间  rotate.setDuration(5000);  rotate.setRepeatCount(Animation.INFINITE);  rotate.setRepeatMode(Animation.RESTART);  imageView.setAnimation(rotate);  rotate.start();

 

4.缩放

  /*   * fromX, toX, 从坐标什么地址开始到什么坐标,0,表示当前 fromY, toY,   * pivotXType, 旋转的中心点   * pivotXValue, 类型, pivotYType, pivotYValue   */  ScaleAnimation scale = new ScaleAnimation(1, 2, 1, -2,      Animation.RELATIVE_TO_SELF, -2, Animation.RELATIVE_TO_SELF, 3);  // 播放显示时间  scale.setDuration(5000);  scale.setRepeatCount(Animation.INFINITE);  scale.setRepeatMode(Animation.RESTART);  imageView.setAnimation(scale);  scale.start();

 

5.透明度

  /*   * fromAlpha, 从什么透明度开始   * toAlpha 到什么透明度结束   */  AlphaAnimation alpha = new AlphaAnimation(1, 0);  // 播放显示时间  alpha.setDuration(2000);  alpha.setRepeatCount(Animation.INFINITE);  alpha.setRepeatMode(Animation.REVERSE);      imageView.setAnimation(alpha);      alpha.start();}

 

6.集合

就是建立一个
AnimationSet set = new AnimationSet();set.addAnimation(scale);  set.addAnimation(rotate);  set.addAnimation(translate);  set.start();

 

就可以播放多个动画

7.
在res/目录下建立anim文件目录
 <!--     如果平移的数值是数字,那么表示的是绝对值    如果是百分比,那么表明是自己的宽高的倍数    如果是百分比加上 p,那么表明是自己的父元素的宽高的倍数     --><??><set ="http://schemas.android.com/apk/res/android" ><translate   android:fromXDelta="200%"  android:toXDelta="200%"  android:fromYDelta="-100%"  android:toYDelta="200%"  android:duration="4000"  android:repeatCount="infinite"  android:repeatMode="reverse"/>  <rotate    android:fromDegrees="0"    android:toDegrees="360"    android:toYScale="0.0"    android:pivotX="50%"    android:pivotY="50%"    android:duration="4000"    android:repeatCount="infinite"    android:repeatMode="reverse"/></set>

 

加载使用AnimationUtils.load方法加载

Animation animation = AnimationUtils.loadAnimation(this, R.anim.animation_set);  imageView.startAnimation(animation);

 

8.帧动画

一般都用代码控制

/** * 水平 * * @param v */public void translate(View v) {  /**   * 参数一: 谁去播放这个动画 参数二: 属性名字 想要改变x方向的移动 参数三:动画执行的数值   */  ObjectAnimator objectAnimatrX = ObjectAnimator.ofFloat(imageView,      "translationX", -50, 50);  ObjectAnimator objectAnimatrY = ObjectAnimator.ofFloat(imageView,      "translationY", 0, 60);  objectAnimatrX.setDuration(2000);  objectAnimatrX.setRepeatCount(ObjectAnimator.INFINITE);  objectAnimatrX.setRepeatMode(ObjectAnimator.REVERSE);  objectAnimatrX.start();}/** * 转换 * * @param v */public void rotate(View v) {  ObjectAnimator rotateX = ObjectAnimator.ofFloat(imageView, "rotationX", 0,360);  ObjectAnimator rotateY = ObjectAnimator.ofFloat(imageView, "rotationY", 0,360);  rotateX.setDuration(3000);  rotateX.setRepeatMode(Animation.REVERSE);  //rotateX.setRepeatCount(Animation.INFINITE);  rotateY.setDuration(3000);  rotateY.setRepeatMode(Animation.REVERSE);  //rotateY.setRepeatCount(Animation.INFINITE);  AnimatorSet set = new AnimatorSet();  set.playSequentially(rotateX,rotateY);  set.start();}/** * 绽放 * * @param v */public void scale(View v) {  ObjectAnimator scaleX = ObjectAnimator.ofFloat(imageView, "scaleX", 2.0f,5f);  ObjectAnimator scaleY = ObjectAnimator.ofFloat(imageView, "scaleY", 2.0f,5f);  scaleX.setDuration(3000);  scaleX.setRepeatMode(Animation.REVERSE);  scaleX.setRepeatCount(Animation.INFINITE);  scaleY.setDuration(3000);  scaleY.setRepeatMode(Animation.REVERSE);  scaleY.setRepeatCount(Animation.INFINITE);  AnimatorSet set = new AnimatorSet();  set.playTogether(scaleX,scaleY);  set.start();}/** * 透明 * * @param v */public void alpha(View v) {  ObjectAnimator alpha = ObjectAnimator.ofFloat(imageView, "alpha", 1.0f,0f);  alpha.setDuration(3000);  alpha.setRepeatMode(Animation.REVERSE);  alpha.setRepeatCount(Animation.INFINITE);  alpha.start();}/** * 集合 * * @param v */public void set(View v) {  /**   * 参数一: 谁去播放这个动画 参数二: 属性名字 想要改变x方向的移动 参数三:动画执行的数值   */  ObjectAnimator objectAnimatrX = ObjectAnimator.ofFloat(imageView,      "translationX", -50, 100);  ObjectAnimator objectAnimatrY = ObjectAnimator.ofFloat(imageView,      "translationY", -70, 100);  objectAnimatrX.setDuration(2000);  //objectAnimatrX.setRepeatCount(ObjectAnimator.INFINITE);  objectAnimatrX.setRepeatMode(ObjectAnimator.REVERSE);  objectAnimatrY.setDuration(2000);  //objectAnimatrY.setRepeatCount(ObjectAnimator.INFINITE);  objectAnimatrY.setRepeatMode(ObjectAnimator.REVERSE);  AnimatorSet set = new AnimatorSet();  //set.playTogether(objectAnimatrX,objectAnimatrY);  set.playSequentially(objectAnimatrX,objectAnimatrY);  set.start();}

 

如果需要 用

AnimatorSet set = (AnimatorSet) AnimatorInflater.loadAnimator(myContext,R.anim.property_animator);set.setTarget(myObject);set.start();

 




原标题:安卓第十八天笔记

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

姜洛智:https://www.goluckyvip.com/tag/34655.html
姜齐放:https://www.goluckyvip.com/tag/34656.html
姜珊珊:https://www.goluckyvip.com/tag/34657.html
僵尸店铺:https://www.goluckyvip.com/tag/34658.html
僵尸链接:https://www.goluckyvip.com/tag/34659.html
ACOS:https://www.goluckyvip.com/tag/3466.html
湘西游轮六 湘江游轮夜游:https://www.vstour.cn/a/411226.html
携程旅游网折扣优惠最新攻略(携程旅游网更佳折扣优惠):https://www.vstour.cn/a/411227.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流