怎么在Android应用中添加一个添加物品动画
这篇文章将为大家详细讲解有关怎么在Android应用中添加一个添加物品动画,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
创新互联是一家专注网站建设、网络营销策划、微信小程序开发、电子商务建设、网络推广、移动互联开发、研究、服务为一体的技术型公司。公司成立十多年以来,已经为数千家垃圾桶各业的企业公司提供互联网服务。现在,服务的数千家客户与我们一路同行,见证我们的成长;未来,我们一起分享成功的喜悦。
开发环境:AndroidStudio2.1.2+gradle-2.10
涉及知识:1.沉浸式状态栏,2.单位精度计算(价格),3.List之Iterator。
部分代码:
public class MainActivity extends AppCompatActivity implements FoodAdapter.FoodActionCallback { private ListView listView; private TextView goods_all_pricetv; private TextView good_numtv; private Listlist; private List selectList = new ArrayList<>(); private FoodAdapter adapter = null; @Override protected void onCreate(@Nullable final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //沉浸式状态栏 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { //透明状态栏 getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); //透明导航栏 getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); } listView = (ListView) findViewById(R.id.listView); goods_all_pricetv = (TextView) findViewById(R.id.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, "你一共加入购物车" + good_numtv.getText() + "份商品,总价格为:" + goods_all_pricetv.getText(), Toast.LENGTH_SHORT).show(); } else { Toast.makeText(MainActivity.this, "你的购物车为空", Toast.LENGTH_SHORT).show(); } } }); initData(); } private void initData() { list = AppConfig.factoryFoods(); adapter = new FoodAdapter(this, list, this); listView.setAdapter(adapter); } //添加商品动画 @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.addView(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(); } //减少商品 @Override public void reduceGood(int position) { FoodModel model = list.get(position); model.setNum(model.getNum() - 1); adapter.notifyDataSetChanged(); calculatePrice(); } //购物车份数+总价格计算 private void calculatePrice() { selectList.clear(); double price = 0; int num = 0; Iterator 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) + "元"); good_numtv.setText(num + ""); } }
关于怎么在Android应用中添加一个添加物品动画就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
网页标题:怎么在Android应用中添加一个添加物品动画
网页URL:http://ybzwz.com/article/pcppis.html