安卓动画的使用 位移动画和缩放动画



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);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值