怎么样建网站啊,网站建设 服务流程,seo公司名字,网站建设seo合同书本文实例为大家分享了Android添加商品进购物车的具体代码#xff0c;供大家参考#xff0c;具体内容如下1、首先展示下效果图2、讲一下思路#xff0c;小球由加号位置运动到购物车位置#xff0c;首先得获得这两个点在整个屏幕中的坐标#xff0c;然后分别计算这两个点的横…本文实例为大家分享了Android添加商品进购物车的具体代码供大家参考具体内容如下1、首先展示下效果图2、讲一下思路小球由加号位置运动到购物车位置首先得获得这两个点在整个屏幕中的坐标然后分别计算这两个点的横纵坐标的差值再通过TranslateAnimation这个类设置小球在X、Y方向上的偏移量最后通过AnimationSet这个类将这两个动画放在一起执行。这是小球运动的动画还有就是购物车变大缩小的动画。这个动画通过ObjectAnimator的ofFloat的方法设置缩放要注意的是当小球落下的时候购物车才开始动画所以要设置一下setStartDelay这个方法。3、具体的代码我就贴一下动画部分的代码如果想要这个Demo看下我最后贴出的Github的地址Overridepublic void setAnim(View view) {// TODO Auto-generated method stubint[] start_location new int[2];// 一个整型数组用来存储按钮在屏幕的X,Y坐标view.getLocationInWindow(start_location);// 购买按钮在屏幕中的坐标buyImg new ImageView(this);// 动画的小圆圈buyImg.setImageResource(R.drawable.sign);// 设置buyImg的图片setAnim(buyImg, start_location);}/*** hdh: 创建动画层** return*/private ViewGroup createAnimLayout() {ViewGroup rootView (ViewGroup) this.getWindow().getDecorView();// 获得Window界面的最顶层LinearLayout animLayout new LinearLayout(this);LinearLayout.LayoutParams lp new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);animLayout.setLayoutParams(lp);//animLayout.setId();animLayout.setBackgroundResource(android.R.color.transparent);rootView.addView(animLayout);return animLayout;}/*** hdh:** param vp* param view* param location* return*/private View addViewToAnimLayout(final ViewGroup vp, final View view, int[] location) {int x location[0];int y location[1];LinearLayout.LayoutParams lp new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);lp.leftMargin x;lp.topMargin y;view.setLayoutParams(lp);return view;}/*** hdh:动画** param v* param start_location*/private void setAnim(final View v, int[] start_location) {anim_mask_layout null;anim_mask_layout createAnimLayout();anim_mask_layout.addView(v);View view addViewToAnimLayout(anim_mask_layout, v, start_location);int[] end_location new int[2];// 存储动画结束位置的X,Y坐标text_chart_num.getLocationInWindow(end_location);// 将购物车的位置存储起来// 计算位移int endX end_location[0] - start_location[0];// 动画位移的X坐标int endY end_location[1] - start_location[1];// 动画位移的y坐标TranslateAnimation translateAnimationX new TranslateAnimation(0, endX, 0, 0);translateAnimationX.setInterpolator(new LinearInterpolator());// 设置此动画的加速曲线。默认为一个线性插值。translateAnimationX.setRepeatCount(0);// 动画重复的次数translateAnimationX.setFillAfter(true);TranslateAnimation translateAnimationY new TranslateAnimation(0, 0, 0, endY);translateAnimationY.setInterpolator(new AccelerateInterpolator());translateAnimationY.setRepeatCount(0);// 动画重复次数translateAnimationY.setFillAfter(true);AnimationSet set new AnimationSet(false);set.setFillAfter(false);set.addAnimation(translateAnimationX);set.addAnimation(translateAnimationY);set.setDuration(1000);view.startAnimation(set);set.setAnimationListener(new Animation.AnimationListener() {Overridepublic void onAnimationStart(Animation animation) {// TODO Auto-generated method stubv.setVisibility(View.VISIBLE);}Overridepublic void onAnimationRepeat(Animation animation) {// TODO Auto-generated method stub}Overridepublic void onAnimationEnd(Animation animation) {// TODO Auto-generated method stubv.setVisibility(View.GONE);}});ObjectAnimator anim ObjectAnimator//.ofFloat(view, scale, 1.0F, 1.5F, 1.0f)//.setDuration(500);//anim.setStartDelay(1000);anim.start();anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {Overridepublic void onAnimationUpdate(ValueAnimator animation) {float cVal (Float) animation.getAnimatedValue();image_chart.setScaleX(cVal);image_chart.setScaleY(cVal);text_chart_num.setScaleX(cVal);text_chart_num.setScaleY(cVal);}});}4、GitHub地址点击打开链接以上就是本文的全部内容希望对大家的学习有所帮助也希望大家多多支持脚本之家。