Shopping Cart animation (Android) and shopping cart animation android

Source: Internet
Author: User

Shopping Cart animation (Android) and shopping cart animation android

Shopping Cart animation (Android)

 

Preface: When we write shopping mall projects, we usually have the function of adding Shopping Cart. When we add shopping cart, there will be some parabolic animations. Recently, this function has been implemented, I wrote one using another demo.

 

Effect:

 

 

Development Environment: AndroidStudio2.1.2 + gradle-2.10

 

 

Knowledge:1. immersive status bar, 2. Unit precision calculation (price), 3. List Iterator.

 

Some code:

Public class MainActivity extends AppCompatActivity implements FoodAdapter. foodActionCallback {private ListView listView; private TextView goods_all_pricetv; private TextView good_numtv; private List <FoodModel> list; private List <FoodModel> selectList = new ArrayList <> (); private FoodAdapter adapter = null; @ Override protected void onCreate (@ Nullable final Bundle savedInstanceState) {super. onCrea Te (savedInstanceState); setContentView (R. layout. activity_main); // immersive status bar if (Build. VERSION. SDK_INT> = Build. VERSION_CODES.KITKAT) {// transparent status bar getWindow (). addFlags (WindowManager. layoutParams. FLAG_TRANSLUCENT_STATUS); // transparent navigation bar getWindow (). addFlags (WindowManager. layoutParams. FLAG_TRANSLUCENT_NAVIGATION);} listView = (ListView) findViewById (R. id. listView); goods_all_pricetv = (TextView) findViewById (R. I D. goods_all_pricetv); good_numtv = (TextView) findViewById (R. id. good_numtv); findViewById (R. id. goods_submit_ TV ). setOnClickListener (new View. onClickListener () {@ Override public void onClick (View v) {if (null! = SelectList & selectList. size ()> 0) {Toast. makeText (MainActivity. this, "you join the shopping cart" + good_numtv.getText () + ", total price:" + goods_all_pricetv.getText (), Toast. LENGTH_SHORT ). show ();} else {Toast. makeText (MainActivity. this, "your shopping cart is empty", Toast. LENGTH_SHORT ). show () ;}}); initData () ;}private void initData () {list = AppConfig. factoryFoods (); adapter = new FoodAdapter (this, list, this); listView. se TAdapter (adapter);} // Add item animation @ Override public void addAction (View view, int item) {ShoppingCartAnimationView shoppingCartAnimationView = new ShoppingCartAnimationView (this ); int position [] = new int [2]; view. getLocationInWindow (position); shoppingCartAnimationView. setStartPosition (new Point (position [0], position [1]); ViewGroup rootView = (ViewGroup) this. getWindow (). getDecorView (); rootView. add View (shoppingCartAnimationView); int endPosition [] = new int [2]; good_numtv.getLocationInWindow (endPosition); shoppingCartAnimationView. setEndPosition (new Point (endPosition [0], endPosition [1]); shoppingCartAnimationView. startBeizerAnimation (); FoodModel model = list. get (item); model. setNum (model. getNum () + 1); adapter. notifyDataSetChanged (); calculatePrice () ;}// reduce commodity @ Override public void reduce Good (int position) {FoodModel model = list. get (position); model. setNum (model. getNum ()-1); adapter. notifyDataSetChanged (); calculatePrice () ;}// Number of cart parts + total price calculation private void calculatePrice () {selectList. clear (); double price = 0; int num = 0; Iterator <FoodModel> iterator = list. iterator (); while (iterator. hasNext () {FoodModel model = iterator. next (); if (model. getNum ()! = 0) {selectList. add (model); price + = model. getPrice () * model. getNum (); num + = model. getNum () ;}} goods_all_pricetv.setText ("$" + adapter. priceResult (price) + "Yuan"); good_numtv.setText (num + "");}}

 

Download source code...

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.