亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

安卓寫一個球彈出的動畫

標簽:
Android

效果图:

https://img1.sycdn.imooc.com//5c1b4f6d0001c9b006461114.jpg

xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:background="@android:color/white"
                android:orientation="vertical">

    <ImageView
        android:id="@+id/sat_main"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentBottom="true"
        android:layout_marginLeft="5dp"
        android:class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="@drawable/sat_main"
        />


    <ImageView
        android:id="@+id/sat_item"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentBottom="true"
        android:visibility="gone"
        />

    <ImageView
        android:id="@+id/clone_item"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentBottom="true"
        android:visibility="gone"
        />


</RelativeLayout>

这3个ImageView都在屏幕的底部,clone_item需要固定在球弹起的最高位置:

球弹出去的动画:

public static Animation createItemOutAnimation(Context context, int index, long expandDuration, int x, int y){
       
       AlphaAnimation alphaAnimation = new AlphaAnimation(0f, 1f);
       long alphaDuration = 60;
       if(expandDuration < 60){
           alphaDuration = expandDuration / 4;
       }
       alphaAnimation.setDuration(alphaDuration);
       alphaAnimation.setStartOffset(0);

       
       TranslateAnimation translate = new TranslateAnimation(0, x, 0, y);
        
       translate.setStartOffset(0);
       translate.setDuration(expandDuration); 
       translate.setInterpolator(context, R.anim.sat_item_overshoot_interpolator);
       
       RotateAnimation rotate = new RotateAnimation(0f, 360f, 
               Animation.RELATIVE_TO_SELF, 0.5f,
               Animation.RELATIVE_TO_SELF, 0.5f);
       

       rotate.setInterpolator(context, R.anim.sat_item_out_rotate_interpolator);
       
       long duration = 100;
       if(expandDuration <= 150){
           duration = expandDuration / 3;
       }
       
       rotate.setDuration(expandDuration-duration);
       rotate.setStartOffset(duration);        
       
       AnimationSet animationSet = new AnimationSet(false);
       animationSet.setFillAfter(false);
       animationSet.setFillBefore(true);
       animationSet.setFillEnabled(true);
               
       //animationSet.addAnimation(alphaAnimation);
       //animationSet.addAnimation(rotate);
       animationSet.addAnimation(translate);
       
       animationSet.setStartOffset(30*index);
       
       return animationSet;
   }

点击按钮时候,按钮本身会旋转:

sat_main.setOnClickListener(new View.OnClickListener() {
   
   @Override
   public void onClick(View v) {
      itemView.setVisibility(View.VISIBLE);
      sat_main.startAnimation(mainRotateLeft);
      itemView.startAnimation(itemOut);
   }
});
 mainRotateLeft = AnimationUtils.loadAnimation(context, R.anim.sat_main_rotate_left);
<?xml version="1.0" encoding="utf-8"?>
<rotate    xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/decelerate_interpolator"    
   android:fromDegrees="0"
   android:toDegrees="-135"        
   android:pivotX="50%"
   android:pivotY="50%"
   android:duration="300" 
   android:fillAfter="true"
   android:fillEnabled="true"/>

代码在:https://github.com/nickgao1986/StepSport

點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
全棧工程師
手記
粉絲
6509
獲贊與收藏
303

關注作者,訂閱最新文章

閱讀免費教程

  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消