Android屬性動畫

來源:互聯網
上載者:User

標籤:


package com.example.administrator.mystudent.PropertyAnimation;import android.animation.AnimatorSet;import android.animation.ObjectAnimator;import android.animation.PropertyValuesHolder;import android.os.Bundle;import android.view.View;import android.view.animation.AnimationSet;import android.view.animation.BounceInterpolator;import android.view.animation.TranslateAnimation;import android.widget.Button;import android.widget.ImageView;import com.example.administrator.mystudent.R;/** * Created by hyang on 2016/8/26. * 屬性動畫學習 */public class PropertyAnimationActivity extends android.app.Activity{    private ImageView img;    private Button button;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_property_animation);        img= (ImageView) findViewById(R.id.iv_img);        button= (Button) findViewById(R.id.btn);        button.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                // setAnimation1();                //setAnimation2();                //setAnimation3();                setAnimation4();            }        });    }   /**     * Tween動畫     */    private void setAnimation1(){        TranslateAnimation animation=new TranslateAnimation(0,200,0,0);        animation.setDuration(3000);        //animation.setFillAfter(true);//停留在動畫完成的位置        img.startAnimation(animation);    }    /**     * 屬性動畫     * 方式1     */    private void setAnimation2(){        ObjectAnimator.ofFloat(img,"translationX",0,200f).setDuration(3000).start();        ObjectAnimator.ofFloat(img,"rotation",0,360f).setDuration(3000).start();    }    /**     * 屬性動畫     * 方式2     */    private void setAnimation3(){        PropertyValuesHolder p1=PropertyValuesHolder.ofFloat("translationX",0,200f);        PropertyValuesHolder p2=PropertyValuesHolder.ofFloat("rotation",0,360f);        ObjectAnimator.ofPropertyValuesHolder(img,p1,p2).setDuration(3000).start();    }    /**     * 屬性動畫     * 方式3     * 有動畫順序     */    private void setAnimation4(){        ObjectAnimator objectAnimator1=ObjectAnimator.ofFloat(img,"translationX",0,200f);        ObjectAnimator objectAnimator2=ObjectAnimator.ofFloat(img,"rotation",0,360f);        //建立android提供的幾種動畫效果(在Android的APIdemo中)        objectAnimator1.setInterpolator(new BounceInterpolator());        AnimatorSet animatorSet=new AnimatorSet();        //animatorSet.playSequentially(objectAnimator1,objectAnimator2);        //按順序播放動畫        animatorSet.play(objectAnimator1).after(objectAnimator2);        animatorSet.setDuration(3000);        animatorSet.start();    }}

 


Android屬性動畫

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.