android 仿心跳動畫

1.起初 我也只是在anim 文件夾里 寫了一個drawable文件 可是沒有停歇 只是不停的縮放

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator"
    android:shareInterpolator="true"
 >
    <!-- 定義縮放變換 -->
    <scale android:fromXScale="0.8"
        android:toXScale="1"
        android:fromYScale="0.8"
        android:toYScale="1"
        android:pivotX="50%"
        android:pivotY="50%"
        android:repeatCount="-1"
        android:repeatMode="reverse"
        android:duration="500"/>
</set>

2.為了又一個延遲時間 匠襟,九牛二虎之力 一個動畫完成 開啟另一個動畫

 final ScaleAnimation animation0 = new ScaleAnimation(0.8f, 1f, 0.8f, 1f,
                Animation.RELATIVE_TO_SELF, 0.5f,
                Animation.RELATIVE_TO_SELF, 0.5f);
        animation0.setFillAfter(true);
        animation0.setDuration(250);

        final ScaleAnimation animation1 = new ScaleAnimation(1f,0.8f, 1f, 0.8f,
                Animation.RELATIVE_TO_SELF, 0.5f,
                Animation.RELATIVE_TO_SELF, 0.5f);
        animation1.setFillAfter(true);
        animation1.setDuration(200);


        animation0.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        imgHeartbeat.startAnimation(animation1);
                    }
                },0);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }
        });
        animation1.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        imgHeartbeat.startAnimation(animation0);
                    }
                },1000  );
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });

        imgHeartbeat.startAnimation(animation0);

廢棄的代碼 有待研究

  ObjectAnimator animator1 = ObjectAnimator.ofFloat(imgHeartbeat, "scaleX", 1f, 1.2f, 1);
        animator1.setDuration(500);
//        animator1.setRepeatCount(-1);


        ObjectAnimator animator2 = ObjectAnimator.ofFloat(imgHeartbeat, "scaleY", 1f, 1.2f, 1);
        animator2.setDuration(500);
//        animator2.setRepeatCount(-1);

        ObjectAnimator animator3 = ObjectAnimator.ofFloat(imgHeartbeat, "scaleX", 1, 0.1f, 1);
        animator3.setDuration(2000);
//        animator3.setRepeatCount(-1);

        ObjectAnimator animator4 = ObjectAnimator.ofFloat(imgHeartbeat, "scaleY", 1, 0.1f, 1);
        animator4.setDuration(2000);
//        animator4.setRepeatCount(-1);


        ObjectAnimator animator5 = ObjectAnimator.ofFloat(imgHeartbeat, "scaleX", 1f, 1f, 1);
        animator5.setDuration(3000);
//        animator5.setRepeatCount(-1);;

//        Scal
        AnimatorSet set=new AnimatorSet();

        set.play(animator1).with(animator2);
        set.play(animator3).with(animator4);
        set.play(animator3).after(animator1);
        set.play(animator5).after(animator3);
        set.setDuration(3000);

        set.setInterpolator(new LinearInterpolator());
//        set.start();
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末竹海,一起剝皮案震驚了整個濱河市蛙奖,隨后出現(xiàn)的幾起案子按灶,更是在濱河造成了極大的恐慌曼库,老刑警劉巖晶默,帶你破解...
    沈念sama閱讀 216,919評論 6 502
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件矛洞,死亡現(xiàn)場離奇詭異微姊,居然都是意外死亡酸茴,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,567評論 3 392
  • 文/潘曉璐 我一進店門兢交,熙熙樓的掌柜王于貴愁眉苦臉地迎上來薪捍,“玉大人,你說我怎么就攤上這事配喳±掖” “怎么了?”我有些...
    開封第一講書人閱讀 163,316評論 0 353
  • 文/不壞的土叔 我叫張陵晴裹,是天一觀的道長被济。 經常有香客問我,道長涧团,這世上最難降的妖魔是什么只磷? 我笑而不...
    開封第一講書人閱讀 58,294評論 1 292
  • 正文 為了忘掉前任经磅,我火速辦了婚禮,結果婚禮上钮追,老公的妹妹穿的比我還像新娘预厌。我一直安慰自己,他們只是感情好元媚,可當我...
    茶點故事閱讀 67,318評論 6 390
  • 文/花漫 我一把揭開白布轧叽。 她就那樣靜靜地躺著,像睡著了一般刊棕。 火紅的嫁衣襯著肌膚如雪犹芹。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,245評論 1 299
  • 那天鞠绰,我揣著相機與錄音腰埂,去河邊找鬼。 笑死蜈膨,一個胖子當著我的面吹牛屿笼,可吹牛的內容都是我干的。 我是一名探鬼主播翁巍,決...
    沈念sama閱讀 40,120評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼驴一,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了灶壶?” 一聲冷哼從身側響起肝断,我...
    開封第一講書人閱讀 38,964評論 0 275
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎驰凛,沒想到半個月后胸懈,有當地人在樹林里發(fā)現(xiàn)了一具尸體,經...
    沈念sama閱讀 45,376評論 1 313
  • 正文 獨居荒郊野嶺守林人離奇死亡恰响,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 37,592評論 2 333
  • 正文 我和宋清朗相戀三年趣钱,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片胚宦。...
    茶點故事閱讀 39,764評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡首有,死狀恐怖,靈堂內的尸體忽然破棺而出枢劝,到底是詐尸還是另有隱情井联,我是刑警寧澤,帶...
    沈念sama閱讀 35,460評論 5 344
  • 正文 年R本政府宣布您旁,位于F島的核電站烙常,受9級特大地震影響,放射性物質發(fā)生泄漏被冒。R本人自食惡果不足惜军掂,卻給世界環(huán)境...
    茶點故事閱讀 41,070評論 3 327
  • 文/蒙蒙 一轮蜕、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧蝗锥,春花似錦跃洛、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,697評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至穴张,卻和暖如春细燎,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背皂甘。 一陣腳步聲響...
    開封第一講書人閱讀 32,846評論 1 269
  • 我被黑心中介騙來泰國打工玻驻, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人偿枕。 一個月前我還...
    沈念sama閱讀 47,819評論 2 370
  • 正文 我出身青樓璧瞬,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 44,665評論 2 354

推薦閱讀更多精彩內容