Android实现添加商品到购物车动画效果

  

本文实例为大家分享了Android添加商品到购物车的具体代码,供大家参考,具体内容如下

  

<>强实现需求
  

  

在商品列表页面中,从列表项添加商品时,实现一个动画,给人感觉像是在添加商品到购物车。

  

<>强思路
  

  

1,获取各个动画执行对象的起点和终点的坐标,利用PathMeasure绘制绘制贝塞尔曲线;
  2、为商品图片设置属性动画;
  3,为动画设置addUpdateListene监听器,更新视图的坐标。

  

<>强效果图:

  

 Android实现添加商品到购物车动画效果

  

MainActivity.java         包com.zlw.yzm.demo;      进口android.animation.Animator;   进口android.animation.ValueAnimator;   进口android.graphics.Path;   进口android.graphics.PathMeasure;   进口android.os.Bundle;   进口android.support.v7.app.AppCompatActivity;   进口android.support.v7.widget.LinearLayoutManager;   进口android.support.v7.widget.RecyclerView;   进口android.util.Log;   进口android.view.View;   进口android.view.ViewGroup;   进口android.view.animation.LinearInterpolator;   进口android.widget.ImageView;   进口android.widget.RelativeLayout;   进口android.widget.TextView;      进口com.zlw.yzm.demo.view.AmountView;      进口java.util.ArrayList;   进口java.util.HashMap;   进口并不知道;   进口java.util.Map;      公开课MainActivity延伸AppCompatActivity {      私人RecyclerView rvGoodsList;   私人ImageView ivGotoGouWuChe;   私人RelativeLayout llContainer;      私人ListproductList;   私人PathMeasure mPathMeasure;/* *   *存储商品列表中对应的位置的商品数量   */私人Map<整数,Integer>,amountMap=new HashMap<的在();/* *   *贝塞尔曲线中间过程的点的坐标   */私人浮动[]mCurrentPosition=new浮动[2];      @Override   保护voidbrush: xml; ">   & lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比;   & lt; RelativeLayout xmlns: android=" http://schemas.android.com/apk/res/android "   xmlns:工具=" http://schemas.android.com/tools "   android: id=癅 + id/rlContainer”   android: layout_width=" match_parent "   android: layout_height=" match_parent "   工具:上下文=癱om.zlw.yzm.demo.MainActivity”比;      & lt; ImageView   android: id=癅 + id/main_iv_goto_gwche”   android: layout_width=" 30 dp "   android: layout_height=" 30 dp "   android: layout_alignParentBottom=" true "   android: layout_alignParentRight=" true "   android: src=" https://www.yisu.com/zixun/@drawable gouwuche "/比;      & lt; android.support.v7.widget.RecyclerView   android: id=癅 + id/main_rv_goods_list”   android: layout_width=" match_parent "   android: layout_height=" match_parent "   android: layout_above=" @ id/main_iv_goto_gwche”祝辞& lt;/android.support.v7.widget.RecyclerView>   & lt;/RelativeLayout>      

//商品列表中项目的布局
  rl_item.xml

        & lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比;   & lt; RelativeLayout xmlns: android=" http://schemas.android.com/apk/res/android "   android: layout_width=" match_parent "   android: layout_height=皐rap_content”比;      & lt; ImageView   android: id=癅 + id/rv_item_iv_product_Icon”   android: layout_width=" wrap_content "   android: layout_height=" wrap_content "   android: src=" https://www.yisu.com/zixun/@mipmap ic_launcher "/比;         LinearLayout & lt;   android: layout_width=" match_parent "   android: layout_height=" wrap_content "   android: layout_alignBottom=" @ id/rv_item_iv_product_Icon”   android: layout_alignTop=" @ id/rv_item_iv_product_Icon”   android: layout_marginLeft=" 20 dp”   android: layout_toRightOf=" @ id/rv_item_iv_product_Icon”   android:重力=" center_vertical "   面向android:=按怪薄北?      & lt; TextView   android: id=癅 + id/rv_item_tv_product_name”   android: layout_width=" wrap_content "   android: layout_height=" wrap_content "   android:文本=癅string/product_name”/比;      & lt; TextView   android: id=癅 + id/rv_item_tv_product_desc”   android: layout_width=" wrap_content "   android: layout_height=" wrap_content "   android: layout_marginTop=" 5 dp "   android:文本=癅string/product_desc”/比;   & lt;/LinearLayout>      & lt; com.zlw.yzm.demo.view.AmountView   android: id=癅 + id/rv_item_amountview”   android: layout_alignParentRight=" true "   android: layout_centerVertical=" true "   android: layout_marginRight=" 20 dp”   android: layout_width=" wrap_content "   android: layout_height=皐rap_content”比;      & lt;/com.zlw.yzm.demo.view.AmountView>   & lt;/RelativeLayout>

Android实现添加商品到购物车动画效果