成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

Android實(shí)現(xiàn)購物車頁面及購物車效果(點(diǎn)擊動(dòng)畫)

whidy / 3843人閱讀

摘要:效果圖如下思路思考每個(gè)條目中的數(shù)字的更新原理。購物車的動(dòng)畫效果。購物清單怎么顯示這個(gè)我暫時(shí)沒有寫,如果需要的話,可以在我的簡書下給我留言。

效果圖如下:

思路:

(1)思考每個(gè)條目中的數(shù)字的更新原理。

(2)購物車的動(dòng)畫效果。

(3)購物清單怎么顯示(這個(gè)我暫時(shí)沒有寫,如果需要的話,可以在我的簡書下給我留言)。

1.因?yàn)檫M(jìn)入頁面,所有的商品個(gè)數(shù)都顯示為零,所以我用 ArrayList> data,把商品集合都附上零:

        //下面把data都添加0,為了剛開始顯示時(shí),顯示的是0
        for (int i = 0; i < list.size(); i++) {
            HashMap myhashmap = new HashMap();
            myhashmap.put("number", "" + 0);
            data.add(myhashmap);
        }

然后把data傳入Adapter:

     adapter = new MyAdapter(data);

當(dāng)我們對商品進(jìn)行增減時(shí),我們可以通過hashmap來更改,如下是增加商品的部分代碼:

    b = Integer.parseInt((String) data.get(position).get(
                            "number"));
                    data.get(position).put("number", "" + (b + 1));

2.購物車動(dòng)畫效果:

首先獲取點(diǎn)擊時(shí)的XY坐標(biāo),并且設(shè)置動(dòng)畫圖片:

// ball是個(gè)imageview
 startLocation = new int[2];// 一個(gè)整型數(shù)組,用來存儲按鈕的在屏幕的X、Y坐標(biāo)
                   view.getLocationInWindow(startLocation);// 這是獲取購買按鈕的在屏幕的X、Y坐標(biāo)(這也是動(dòng)畫開始的坐標(biāo))
                   ball = new ImageView(MainActivity.this);
                   ball.setImageResource(R.mipmap.sign);// 設(shè)置動(dòng)畫的圖片我的是一個(gè)小球(R.mipmap.sign)

然后是開始執(zhí)行動(dòng)畫:

    private void setAnim(final View v, int[] startLocation) {
       anim_mask_layout = null;
       anim_mask_layout = createAnimLayout(); //創(chuàng)建動(dòng)畫層
       anim_mask_layout.addView(v);//把動(dòng)畫小球添加到動(dòng)畫層
       final View view = addViewToAnimLayout(anim_mask_layout, v,
               startLocation);
       int[] endLocation = new int[2];// 存儲動(dòng)畫結(jié)束位置的X、Y坐標(biāo)
       re_zhongcai_tanchu.getLocationInWindow(endLocation);// re_zhongcai_tanchu是那個(gè)拋物線最后掉落的控件

       // 計(jì)算位移
       int endX = 0 - startLocation[0] + 40;// 動(dòng)畫位移的X坐標(biāo)
       int endY = endLocation[1] - startLocation[1];// 動(dòng)畫位移的y坐標(biāo)
       TranslateAnimation translateAnimationX = new TranslateAnimation(0,
               endX, 0, 0);
       translateAnimationX.setInterpolator(new LinearInterpolator());
       translateAnimationX.setRepeatCount(0);// 動(dòng)畫重復(fù)執(zhí)行的次數(shù)
       translateAnimationX.setFillAfter(true);

       TranslateAnimation translateAnimationY = new TranslateAnimation(0, 0,
               0, endY);
       translateAnimationY.setInterpolator(new AccelerateInterpolator());
       translateAnimationY.setRepeatCount(0);// 動(dòng)畫重復(fù)執(zhí)行的次數(shù)
       translateAnimationX.setFillAfter(true);

       final AnimationSet set = new AnimationSet(false);
       set.setFillAfter(false);
       set.addAnimation(translateAnimationY);
       set.addAnimation(translateAnimationX);
       set.setDuration(800);// 動(dòng)畫的執(zhí)行時(shí)間
       view.startAnimation(set);
       // 動(dòng)畫監(jiān)聽事件
       set.setAnimationListener(new Animation.AnimationListener() {
           // 動(dòng)畫的開始
           @Override
           public void onAnimationStart(Animation animation) {
               v.setVisibility(View.VISIBLE);
               //    Log.e("動(dòng)畫","asdasdasdasd");
           }

           @Override
           public void onAnimationRepeat(Animation animation) {
               // TODO Auto-generated method stub
           }

           // 動(dòng)畫的結(jié)束
           @Override
           public void onAnimationEnd(Animation animation) {
               v.setVisibility(View.GONE);
               set.cancel();
               animation.cancel();
           }
       });

   }

需要注意的是,當(dāng)動(dòng)畫結(jié)束必須關(guān)閉動(dòng)畫:

  v.setVisibility(View.GONE);
              set.cancel();
              animation.cancel();

購物車的彈出清單功能,我沒有寫,需要的話,可以去我的簡書留言.

我的github地址

我的公眾號如下:

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/70244.html

相關(guān)文章

  • 【收藏篇】32篇技術(shù)博文匯總(九月總結(jié))

    摘要:首先先祝大家國慶節(jié)快樂今天距離為我運(yùn)營公眾號已經(jīng)一個(gè)月了,今天把文章整合一下,希望對大家有幫助,也謝謝朋友的支持,我會繼續(xù)堅(jiān)持原創(chuàng),寫更好的文章給大家一視頻獲取學(xué)習(xí)資源分享合集二功能篇實(shí)現(xiàn)金額的語音播報(bào)功能基于模式風(fēng)格的封裝之路炫酷動(dòng)畫跳 showImg(https://segmentfault.com/img/remote/1460000011437678?w=900&h=500);...

    whlong 評論0 收藏0
  • 【收藏篇】32篇技術(shù)博文匯總(九月總結(jié))

    摘要:首先先祝大家國慶節(jié)快樂今天距離為我運(yùn)營公眾號已經(jīng)一個(gè)月了,今天把文章整合一下,希望對大家有幫助,也謝謝朋友的支持,我會繼續(xù)堅(jiān)持原創(chuàng),寫更好的文章給大家一視頻獲取學(xué)習(xí)資源分享合集二功能篇實(shí)現(xiàn)金額的語音播報(bào)功能基于模式風(fēng)格的封裝之路炫酷動(dòng)畫跳 showImg(https://segmentfault.com/img/remote/1460000011437678?w=900&h=500);...

    Eric 評論0 收藏0

發(fā)表評論

0條評論

最新活動(dòng)
閱讀需要支付1元查看
<