您的位置:首页 > 其它

加入购物车动画

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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  动画 imageview exception