安卓动画的使用 位移动画和缩放动画
float lineY=lineRL.getY(); int bottomCartHeight = DisplayUtil.dip2px(getContext(),70);//门店购物车图标总高80 int diffx = DisplayUtil.dip2px(getContext(),15); float minusHeight = DeviceUtil.getScreenHeight()-bottomCartHeight-lineY; Animation translateAnimation=new TranslateAnimation(0,-(DeviceUtil.getScreenWidth()/4-diffx),0,minusHeight); 解读:
public TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta) { throw new RuntimeException("Stub!"); } 默认以VIEW的初始位置fromXDelta:指导View动画起点的位置,这个参数的大小就是代表了距离起点位置的距离大小
toXDeltaL指导View动画终点的位置,这个参数的大小就是代表了移动的距离(经过测试认为应该是相对于动画开始的位置)
如果
public TranslateAnimation(int fromXType, float fromXValue, int toXType, float toXValue, int fromYType, float fromYValue, int toYType, float toYValue) { throw new RuntimeException("Stub!"); } 我们可以修改Type, 来制定fromXValue代表的含义,可以制定是父容器,
RELATIVE_TO_PARENT 0.5 代表移动的距离是父容易的一半
RELATIVE_TO_SELF 0.5 代表移动的距离是自身的一半
ABSOLUTE 100 代表移动的距离就是100个PX(默认就是这种方式)translateAnimation.setStartOffset(0);translateAnimation.setDuration(500);Animation scaleAnimation = new ScaleAnimation(1f,0.05f,1f,0.05f,(DeviceUtil.getScreenWidth()/2)-(DeviceUtil.getScreenWidth()/10),lineY);
解读: public ScaleAnimation(float fromX, float toX, float fromY, float toY, float pivotX, float pivotY) { throw new RuntimeException("Stub!"); }fromX:动画开始时候的VIEW的大小,例如1f,表示原始大小
toX:动画结束时候的VIEW的大小,例如0.5f,表示缩小到原始大小的一半
pivot:
英 [ˈpɪvət] |
缩放中心店默认在VIEW的左上角!
pivotX:指定缩放中心点在横向在距离左上角的位置
pivotY:指定缩放中心店在纵向上距离左上角的位置
VIEW分别围绕两条横纵向的枢轴线按照比例缩放
scaleAnimation.setStartOffset(0);scaleAnimation.setDuration(500);animationSet = new AnimationSet(false);animationSet.addAnimation(scaleAnimation);animationSet.addAnimation(translateAnimation);