获得屏幕尺寸,系统动画和assets文件夹的管理

1.获得屏幕动画(display:显示器;metrics:度量;pixels:像素);
DisplayMetrics displayMetrics = new DisplayMetrics();     //这个就是获得屏幕尺寸得类
this.getWindow.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);     //将屏幕尺寸设置到displayMetrics;
displayMetrics.widthPixels     //屏幕的宽度
displayMetrics. heightPixels     //屏幕的高度
代码:
public Point getScreenSize(){
     DisplayMetrics displayMetrics =  new DisplayMetrics();
      this.getWindow().getWindowManager().
               getDefaultDisplay().getMetrics(displayMetrics);
     Point point =  new Point(displayMetrics.widthPixels
                                     ,displayMetrics.heightPixels );
      return point;
}

2.设置系统动画(
animation:动画;alpha:透明;rotate:旋转;scale: 缩放;
translate:平移;restart:重新开始;reverse:颠倒;degrees:角度);
一共有四种系统屏幕动画:
Animation动态父类,有4个子类
AlphaAnimation 透明动画
RotateAnimation 旋转动画
ScaleAnimation 缩放动画
TranslateAnimation 平移动画

动画中的一些共有方法:
duration:动画的播放时间
fillAfter fillBefore:动画播放完后是停在后面还是前面
fillEnabled:定义在set中
repeatCount:重复次数
repeatMode:动画重复模式,有restart和reverse两个值可选(restart是从头开始循环,reverse是从尾开始循环)
startOffset: 动画的开始延迟时间

interpolator: 插速器
AccelerateDecelerateInterpolator 在动画开始与结束的地方速率改变比较慢,在中间的时候加速
AccelerateInterpolator  在动画开始的地方速率改变比较慢,然后开始加速
DecelerateInterpolator 在动画开始的地方快然后慢
AnticipateInterpolator 开始的时候向后然后向前甩
AnticipateOvershootInterpolator 开始的时候向后然后向前甩一定值后返回最后的值
BounceInterpolator   动画结束的时候弹起
CycleInterpolator 动画循环播放特定的次数,速率改变沿着正弦曲线
LinearInterpolator   以常量速率改变
OvershootInterpolator    向前甩一定值后再回到原来位置

代码(建立对象作为参数):
animation.setInterpolator ( new AccelerateInterpolator());

(1)AlphaAnimation 透明动画
//建立动画对象,参数为(fromAlpha起始透明度,toAlpha结束透明度)
AlphaAnimation alphaAnimation =  new  AlphaAnimation(0, 1);
alphaAnimation.setDuration(1000);//设置动画播放时间 
alphaAnimation.setFillAfter( true );//动画播放完后停在后面
alphaAnimation.setInterpolator(  new  AccelerateInterpolator());//设置速度
iv .startAnimation( alphaAnimation);//设置动画

(2)RotateAnimation旋转动画
/**
参数含义:
fromDegrees     旋转起始角度
toDegrees     旋转结束角度
pivotX、pivotY    旋转中心点的X、Y坐标

*/
RotateAnimation rotateAnimation =  new  RotateAnimation(0, 360, 
                                             point.  x /2, point. y /2);
rotateAnimation.setDuration(1000);
rotateAnimation.setFillAfter(  true );
rotateAnimation.setInterpolator(  new  DecelerateInterpolator());
iv .startAnimation(rotateAnimation);

(3)ScaleAnimation缩放动画
/**
参数含义
fromXScale、fromYScale     缩放起始比例
toXScale、toYScale     缩放结束比例
pivotX、pivotY     缩放中心点坐标

*/
ScaleAnimation scaleAnimation =  new  ScaleAnimation(
                                        0, 1, 0, 1,point. x /2,point.  y /2);
scaleAnimation.setDuration(1000);
scaleAnimation.setFillAfter(  true );
scaleAnimation.setInterpolator(  new  AccelerateInterpolator());
iv .startAnimation(scaleAnimation);

(4)TranslateAnimation平移动画
/**
参数含义
fromXDelta、toXDelta     初始X、结束X坐标
fromYDelta、toYDelta     初始Y、结束Y坐标
*/
TranslateAnimation translateAnimation =  new  TranslateAnimation(point. x , 0, 0,
                                                                  0);
translateAnimation.setDuration(1000);
translateAnimation.setFillAfter(  true );
translateAnimation.setInterpolator(  new  AccelerateInterpolator());
iv .startAnimation( translateAnimation);

(5)动画监听器
public void setAnimationListener (Animation.AnimationListener listener)     //事件处理
onAnimationEnd(Animation animation)     //动画结束时调用
onAnimationRepeat(Animation animation)     //重复动画时调用
onAnimationStart(Animation animation)     //动画开始时调用

3.Assert文件夹的管理
AssetManager   assetManager  =  this .getAssets();      //获得Asset的的管理器
String[] imgsName =  assetManager  .list ( "imgs" );     //这个方法会返回每一个资源字符串数组

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值