欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android直播app送禮物連擊動(dòng)畫效果(實(shí)例代碼)

 更新時(shí)間:2017年07月12日 09:51:45   作者:yylyingy  
最近在做公司的直播項(xiàng)目,需要實(shí)現(xiàn)一個(gè)觀看端連擊送禮物的控件,下面給大家分享實(shí)例代碼,需要的的朋友參考下吧

最近在做公司的直播項(xiàng)目,需要實(shí)現(xiàn)一個(gè)觀看端連擊送禮物的控件:

直接上代碼:

/**
 * @author yangyinglong on 2017/7/11 16:52.
 * @Description: todo(這里用一句話描述這個(gè)類的作用)
 * @Copyright Copyright (c) 2017 Tuandai Inc. All Rights Reserved.
 */
public class CustomGiftView extends LinearLayout {
  private Timer timer;
  private List<View> giftViewCollection = new ArrayList<>();
  public CustomGiftView(Context context) {
    this(context,null);
  }
  public CustomGiftView(Context context, @Nullable AttributeSet attrs) {
    this(context, attrs,0);
  }
  public CustomGiftView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
    this(context, attrs, defStyleAttr,0);
  }
  public CustomGiftView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);
  }
  /**
   *<br> Description: todo(這里用一句話描述這個(gè)方法的作用)
   *<br> Author:   yangyinglong
   *<br> Date:    2017/7/11 17:40
   */
  public void pause() {
    if (null != timer) {
      timer.cancel();
    }
  }
  public void cancel() {
    if (null != timer) {
      timer.cancel();
    }
  }
  public void resume() {
    clearTiming();
  }
  /**
   * 定時(shí)清除禮物
   */
  private void clearTiming() {
    TimerTask task = new TimerTask() {
      @Override
      public void run() {
        int count = CustomGiftView.this.getChildCount();
        for (int i = 0; i < count; i++) {
          View view = CustomGiftView.this.getChildAt(i);
          CustomRoundView crvheadimage = (CustomRoundView) view.findViewById(R.id.crvheadimage);
          long nowtime = System.currentTimeMillis();
          long upTime = (Long) crvheadimage.getTag();
          if ((nowtime - upTime) >= 3000) {
            final int j = i;
            post(new Runnable() {
              @Override
              public void run() {
                CustomGiftView.this.removeViewAt(j);
              }
            });
//            removeGiftView(i);
            return;
          }
        }
      }
    };
    if (null != timer) {
      timer.cancel();
    }
    timer = new Timer();
    timer.schedule(task, 0, 100);
  }
  /**
   * 添加禮物view,(考慮垃圾回收)
   */
  private View addGiftView() {
    View view = null;
    if (giftViewCollection.size() <= 0) {
      /*如果垃圾回收中沒有view,則生成一個(gè)*/
      view = LayoutInflater.from(getContext()).inflate(R.layout.item_gift, null);
      LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
      lp.topMargin = 10;
      view.setLayoutParams(lp);
      this.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
        @Override
        public void onViewAttachedToWindow(View view) { }
        //復(fù)用Item,當(dāng)一個(gè)View移除時(shí)將它放到池內(nèi)
        @Override
        public void onViewDetachedFromWindow(View view) {
          if (giftViewCollection.size() < 5) {
            giftViewCollection.add(view);
          }
        }
      });
    } else {
      //如果Item池內(nèi)有緩存的view,將它取出來,并從池中刪除
      view = giftViewCollection.get(0);
      giftViewCollection.remove(view);
    }
    return view;
  }
  /**
   *<br> Description: todo(這里用一句話描述這個(gè)方法的作用)
   *<br> Author:   yangyinglong
   *<br> Date:    2017/7/11 16:54
   * @param tag
   */
  public void showGift(String tag) {
    View giftView = this.findViewWithTag(tag);
    if (giftView == null) {/*該用戶不在禮物顯示列表*/
      giftView = addGiftView();/*獲取禮物的View的布局*/
      giftView.setTag(tag);/*設(shè)置view標(biāo)識(shí)*/
      CustomRoundView crvheadimage = (CustomRoundView) giftView.findViewById(R.id.crvheadimage);
      final MagicTextView giftNum = (MagicTextView) giftView.findViewById(R.id.giftNum);/*找到數(shù)量控件*/
      TextView sender = (TextView) giftView.findViewById(R.id.sender);
      sender.setText(tag);
      giftNum.setText("x1");/*設(shè)置禮物數(shù)量*/
      crvheadimage.setTag(System.currentTimeMillis());/*設(shè)置時(shí)間標(biāo)記*/
      giftNum.setTag(1);/*給數(shù)量控件設(shè)置標(biāo)記*/
      this.addView(giftView,0);/*將禮物的View添加到禮物的ViewGroup中*/
//      llgiftcontent.invalidate();/*刷新該view*/
      TranslateAnimation inAnim = (TranslateAnimation) AnimationUtils.loadAnimation(getContext(), R.anim.gift_in);
      giftView.startAnimation(inAnim);/*開始執(zhí)行顯示禮物的動(dòng)畫*/
      inAnim.setAnimationListener(new Animation.AnimationListener() {/*顯示動(dòng)畫的監(jiān)聽*/
        @Override
        public void onAnimationStart(Animation animation) { }
        @Override
        public void onAnimationEnd(Animation animation) {
          //注釋調(diào),第一次添加沒動(dòng)畫
//          giftNumAnim.start(giftNum);
          Log.d("gao","" + CustomGiftView.this.getHeight());
        }
        @Override
        public void onAnimationRepeat(Animation animation) { }
      });
    } else {/*該用戶在禮物顯示列表*/
      for (int i = 0;i < CustomGiftView.this.getChildCount();i ++) {
        if (giftView.equals(CustomGiftView.this.getChildAt(i))) {
          if (i >= 3) {
            CustomGiftView.this.removeView(giftView);
          }
        }
      }
//            llgiftcontent.addView(giftView,0);
      CustomRoundView crvheadimage = (CustomRoundView) giftView.findViewById(R.id.crvheadimage);/*找到頭像控件*/
      MagicTextView giftNum = (MagicTextView) giftView.findViewById(R.id.giftNum);/*找到數(shù)量控件*/
      int showNum = (Integer) giftNum.getTag() + 1;
      giftNum.setText("x"+showNum);
      giftNum.setTag(showNum);
      crvheadimage.setTag(System.currentTimeMillis());
      new NumAnim().start(giftNum);
    }
  }
  /**
   * 數(shù)字放大動(dòng)畫
   */
  public static class NumAnim {
    private Animator lastAnimator = null;
    public void start(View view) {
      if (lastAnimator != null) {
        lastAnimator.removeAllListeners();
        lastAnimator.end();
        lastAnimator.cancel();
      }
      ObjectAnimator anim1 = ObjectAnimator.ofFloat(view, "scaleX",0.7f, 1.5f,1f);
      ObjectAnimator anim2 = ObjectAnimator.ofFloat(view, "scaleY",0.7f, 1.5f,1f);
      AnimatorSet animSet = new AnimatorSet();
      lastAnimator = animSet;
      animSet.setDuration(500);
      animSet.setInterpolator(new OvershootInterpolator());
      animSet.playTogether(anim1, anim2);
      animSet.start();
    }
  }
  public static class GiftInfo {
    private String senderFace;
    private String senderNickName;
    private String giftUrl;
    private int giftID;
    public String getSenderFace() {
      return senderFace;
    }
    public void setSenderFace(String senderFace) {
      this.senderFace = senderFace;
    }
    public String getSenderNickName() {
      return senderNickName;
    }
    public void setSenderNickName(String senderNickName) {
      this.senderNickName = senderNickName;
    }
    public String getGiftUrl() {
      return giftUrl;
    }
    public void setGiftUrl(String giftUrl) {
      this.giftUrl = giftUrl;
    }
    public int getGiftID() {
      return giftID;
    }
    public void setGiftID(int giftID) {
      this.giftID = giftID;
    }
  }
}

以上所述是小編給大家介紹的Android直播app禮物連擊動(dòng)畫效果,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

  • Android子線程與更新UI問題的深入講解

    Android子線程與更新UI問題的深入講解

    首先和其他許多的GUI庫一樣,Android的UI線程是不安全的。所以下面這篇文章主要給大家介紹了關(guān)于Android子線程與更新UI問題的相關(guān)資料,需要的朋友可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-03-03
  • Flutter開發(fā)中的路由參數(shù)處理

    Flutter開發(fā)中的路由參數(shù)處理

    在實(shí)際開發(fā)中,我們經(jīng)常會(huì)需要在頁面跳轉(zhuǎn)的時(shí)候攜帶路由參數(shù),典型的例子就是從列表到詳情頁的時(shí)候,需要攜帶詳情的 id,以便詳情頁獲取對(duì)應(yīng)的數(shù)據(jù)。同時(shí),有些時(shí)候還需要返回時(shí)攜帶參數(shù)返回上一級(jí),以便上級(jí)頁面根據(jù)返回結(jié)果更新。本篇將介紹這兩種情形的實(shí)現(xiàn)。
    2021-06-06
  • android中實(shí)現(xiàn)手機(jī)號(hào)碼的校驗(yàn)的示例代碼

    android中實(shí)現(xiàn)手機(jī)號(hào)碼的校驗(yàn)的示例代碼

    本篇文章主要介紹了android中實(shí)現(xiàn)手機(jī)號(hào)碼的校驗(yàn)的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-09-09
  • Android實(shí)現(xiàn)個(gè)性化的進(jìn)度條

    Android實(shí)現(xiàn)個(gè)性化的進(jìn)度條

    這篇文章主要介紹了Android實(shí)現(xiàn)個(gè)性化的進(jìn)度條 的相關(guān)資料,需要的朋友可以參考下
    2016-07-07
  • 詳解Android如何實(shí)現(xiàn)不同大小的圓角

    詳解Android如何實(shí)現(xiàn)不同大小的圓角

    在開發(fā)過程中,設(shè)計(jì)常常會(huì)有一些比較炫酷的想法,比如兩邊不一樣大小的圓角啦,甚至四角的radius各不相同,對(duì)于這種情況我們該怎么實(shí)現(xiàn)呢,本文小編就和大家來聊聊,需要的朋友可以參考下
    2023-08-08
  • 強(qiáng)制Android應(yīng)用使用某個(gè)Locale的方法

    強(qiáng)制Android應(yīng)用使用某個(gè)Locale的方法

    這篇文章主要介紹了強(qiáng)制Android應(yīng)用使用某個(gè)Locale的方法,涉及Android基于Locale進(jìn)行語言設(shè)置的相關(guān)技巧,需要的朋友可以參考下
    2015-10-10
  • Android ScrollView實(shí)現(xiàn)反彈效果的實(shí)例

    Android ScrollView實(shí)現(xiàn)反彈效果的實(shí)例

    這篇文章主要介紹了 Android ScrollView實(shí)現(xiàn)反彈效果的實(shí)例的相關(guān)資料,這里自定義scrollview 并實(shí)現(xiàn)反彈效果,需要的朋友可以參考下
    2017-07-07
  • Android短信發(fā)送器實(shí)現(xiàn)方法

    Android短信發(fā)送器實(shí)現(xiàn)方法

    這篇文章主要介紹了Android短信發(fā)送器實(shí)現(xiàn)方法,以實(shí)例形式較為詳細(xì)的分析了Android短信發(fā)送器從界面布局到功能實(shí)現(xiàn)的完整步驟與相關(guān)技巧,需要的朋友可以參考下
    2015-09-09
  • Android Studio注釋模板介紹

    Android Studio注釋模板介紹

    這篇文章主要介紹了Android Studio注釋模板介紹,之前Eclipse敲/**加回車,模板就出來了,而Android Studio卻不可以自定義,現(xiàn)在我給大家介紹下用live templates替代,需要的朋友可以參考下
    2015-07-07
  • Android中Notification 提示對(duì)話框

    Android中Notification 提示對(duì)話框

    Notification,俗稱通知,是一種具有全局效果的通知,它展示在屏幕的頂端,首先會(huì)表現(xiàn)為一個(gè)圖標(biāo)的形式,當(dāng)用戶向下滑動(dòng)的時(shí)候,展示出通知具體的內(nèi)容
    2016-01-01

最新評(píng)論