加入购物车动画
2016-04-26 15:31
351 查看
/**
* 将要执行的动画view添加到动画层
*
* @param vg
* @param view
* @param location
* @return
*/
private View addViewToAnimLayout(ViewGroup vg, View view, int[] location) {
int x = location[0];
int y = location[1];
vg.addView(view);
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(
CommonUtils.dp2px(90), CommonUtils.dp2px(90));
lp.leftMargin = x;
lp.topMargin = y;
view.setPadding(5, 5, 5, 5);
view.setLayoutParams(lp);
return view;
}
private void doAnim(Drawable drawable, int[] start_location) {
if (!isClean) {
setAnim(drawable, start_location);
} else {
try {
animation_viewGroup.removeAllViews();
isClean = false;
setAnim(drawable, start_location);
} catch (Exception e) {
e.printStackTrace();
} finally {
isClean = true;
}
}
}
private void setAnim(Drawable drawable, int[] start_location) {
Animation mScaleAnimation = new ScaleAnimation(1.5f, 0.0f, 1.5f, 0.0f, Animation.RELATIVE_TO_SELF, 0.1f, Animation.RELATIVE_TO_SELF, 0.1f);
mScaleAnimation.setDuration(AnimationDuration);
mScaleAnimation.setFillAfter(true);
final ImageView iview = new ImageView(getActivity());
iview.setImageDrawable(drawable);
final View view = addViewToAnimLayout(animation_viewGroup, iview, start_location);
view.setAlpha(0.6f);
int[] end_location = new int[2];
getActivity().findViewById(R.id.main_cart_img).getLocationInWindow(end_location);
int endX = end_location[0] - start_location[0];
int endY = end_location[1] - start_location[1];
Animation mTranslateAnimation = new TranslateAnimation(0, endX, 0, endY);
mTranslateAnimation.setDuration(AnimationDuration);
AnimationSet mAnimationSet = new AnimationSet(true);
mAnimationSet.setFillAfter(true);
mAnimationSet.addAnimation(mScaleAnimation);
mAnimationSet.addAnimation(mTranslateAnimation);
mAnimationSet.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
number++;
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
number--;
if (number == 0) {
isClean = true;
myHandler.sendEmptyMessage(0);
}
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
});
view.startAnimation(mAnimationSet);
}
/**
* 低内存释放
*/
public void onLowMemory() {
// TODO Auto-generated method stub
isClean = true;
try {
animation_viewGroup.removeAllViews();
} catch (Exception e) {
e.printStackTrace();
}
isClean = false;
super.onLowMemory();
}
/**
* @return 创建动画层
*/
private FrameLayout createAnimLayout() {
ViewGroup rootView = (ViewGroup) getActivity().getWindow().getDecorView();
FrameLayout animLayout = new FrameLayout(getActivity());
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
animLayout.setLayoutParams(lp);
animLayout.setBackgroundResource(android.R.color.transparent);
rootView.addView(animLayout);
return animLayout;
}
* 将要执行的动画view添加到动画层
*
* @param vg
* @param view
* @param location
* @return
*/
private View addViewToAnimLayout(ViewGroup vg, View view, int[] location) {
int x = location[0];
int y = location[1];
vg.addView(view);
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(
CommonUtils.dp2px(90), CommonUtils.dp2px(90));
lp.leftMargin = x;
lp.topMargin = y;
view.setPadding(5, 5, 5, 5);
view.setLayoutParams(lp);
return view;
}
private void doAnim(Drawable drawable, int[] start_location) {
if (!isClean) {
setAnim(drawable, start_location);
} else {
try {
animation_viewGroup.removeAllViews();
isClean = false;
setAnim(drawable, start_location);
} catch (Exception e) {
e.printStackTrace();
} finally {
isClean = true;
}
}
}
private void setAnim(Drawable drawable, int[] start_location) {
Animation mScaleAnimation = new ScaleAnimation(1.5f, 0.0f, 1.5f, 0.0f, Animation.RELATIVE_TO_SELF, 0.1f, Animation.RELATIVE_TO_SELF, 0.1f);
mScaleAnimation.setDuration(AnimationDuration);
mScaleAnimation.setFillAfter(true);
final ImageView iview = new ImageView(getActivity());
iview.setImageDrawable(drawable);
final View view = addViewToAnimLayout(animation_viewGroup, iview, start_location);
view.setAlpha(0.6f);
int[] end_location = new int[2];
getActivity().findViewById(R.id.main_cart_img).getLocationInWindow(end_location);
int endX = end_location[0] - start_location[0];
int endY = end_location[1] - start_location[1];
Animation mTranslateAnimation = new TranslateAnimation(0, endX, 0, endY);
mTranslateAnimation.setDuration(AnimationDuration);
AnimationSet mAnimationSet = new AnimationSet(true);
mAnimationSet.setFillAfter(true);
mAnimationSet.addAnimation(mScaleAnimation);
mAnimationSet.addAnimation(mTranslateAnimation);
mAnimationSet.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
number++;
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
number--;
if (number == 0) {
isClean = true;
myHandler.sendEmptyMessage(0);
}
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
});
view.startAnimation(mAnimationSet);
}
/**
* 低内存释放
*/
public void onLowMemory() {
// TODO Auto-generated method stub
isClean = true;
try {
animation_viewGroup.removeAllViews();
} catch (Exception e) {
e.printStackTrace();
}
isClean = false;
super.onLowMemory();
}
/**
* @return 创建动画层
*/
private FrameLayout createAnimLayout() {
ViewGroup rootView = (ViewGroup) getActivity().getWindow().getDecorView();
FrameLayout animLayout = new FrameLayout(getActivity());
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
animLayout.setLayoutParams(lp);
animLayout.setBackgroundResource(android.R.color.transparent);
rootView.addView(animLayout);
return animLayout;
}
相关文章推荐
- Gifski:一个跨平台的高质量 GIF 编码器
- 模仿动画的放大缩小容器
- jQuery 1.9.1源码分析系列(十五)动画处理之缓动动画核心Tween
- Android实现定制返回按钮动画效果的方法
- Android编程UI设计之GridView和ImageView的用法
- 基于Android实现随手指移动的ImageView
- Android中ViewFlipper的使用及设置动画效果实例详解
- Android中ImageView用法实例分析
- jQuery实现美观的多级动画效果菜单代码
- php判断GIF图片是否为动画的方法
- jQuery实现动画效果circle实例
- HTML5游戏引擎LTweenLite实现的超帅动画效果(附demo源码下载)
- 浅析JavaScript动画
- js排序动画模拟-插入排序
- javascript+HTML5的Canvas实现Lab单车动画效果
- 基于javascript实现漂亮的页面过渡动画效果附源码下载
- js实现按钮颜色渐变动画效果
- 超赞的jQuery图片滑块动画特效代码汇总
- jQuery实现连续动画效果实例分析
- 利用jquery制作滚动到指定位置触发动画