属性动画

    public class MainActivity extends Activity {

    private Button button;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        button = (Button) findViewById(R.id.button);
        change();
            }

    int count = 0;
    public void click(View view) {
        count++;
        if(count==1){
            Toast.makeText(this, "你再点下试试?!", 0).show();
            change();
        }

        if(count==2){
            Toast.makeText(this, "还真点啊,敢不敢再点?", 0).show();
            change();}
        if(count==3){
            Toast.makeText(this, "好吧,你再点下看?", 0).show();
            change();}
        if(count==4){
            Toast.makeText(this, "无所谓了,随便点吧", 0).show();
            change();}

    }
    public void change(){
        /*
         * 参数1:要变化的控件UI 
         * 参数2:要怎么变 
         * 参数3:变化的过程 ,可变参数
         */

        // 平移
        // bt.TRANSLATION_X

        ObjectAnimator animator = new ObjectAnimator().ofFloat(button,
                "translationX", 0, 10, 20, 30, 40, 50);
        // 总时常,周期
        animator.setDuration(3000);
        // 重复的次数
        animator.setRepeatCount(3);
        // 重复的类型
        animator.setRepeatMode(ObjectAnimator.REVERSE);
        // 启动
        // animator.start();


        // 旋转
        // bt.setRotation(rotation)
        ObjectAnimator animator2 = ObjectAnimator.ofFloat(button, "rotation",
                0, 10, 20, 30, 40, 50);
        animator2.setDuration(3000);
        animator2.setRepeatCount(2);
        animator2.setRepeatMode(ObjectAnimator.REVERSE);
        // animator2.start();


        // 缩放
        // bt.setScaleX(scaleX)
        ObjectAnimator animator3 = ObjectAnimator.ofFloat(button, "scaleX", 0f,
                0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.8f, 1f);
        animator3.setDuration(3000);
        animator3.setRepeatCount(2);
        animator3.setRepeatMode(ObjectAnimator.REVERSE);
        // animator3.start();


        // 透明
        // bt.setAlpha(alpha)
        ObjectAnimator animator4 = ObjectAnimator.ofFloat(button, "alpha", 0f,
                0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.8f, 1f);
        animator4.setDuration(3000);
        animator4.setRepeatCount(2);
        animator4.setRepeatMode(ObjectAnimator.REVERSE);
        // animator4.start();

        //动画集合
        AnimatorSet set = new AnimatorSet();
        // 一起玩,一起嗨
        set.playTogether(animator, animator2, animator3, animator4);
        set.start();

    } 

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值