动画效果animator

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private Button button1;
    private Button button2;
    private Button button3;
    private Button button4,button5;
    private ImageButton img;

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

    }
//获取的id控件
    private void intByid() {
        button1 = findViewById( R.id.but1 );
        button2 = findViewById( R.id.but2 );
        button3 = findViewById( R.id.but3 );
        button4 = findViewById( R.id.but4 );
        button5 = findViewById( R.id.but5 );
        img = findViewById( R.id.img );
        button1.setOnClickListener( this );
        button2.setOnClickListener( this );
        button3.setOnClickListener( this );
        button4.setOnClickListener( this );
        button5.setOnClickListener( this );
        img.setOnClickListener( new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText( MainActivity.this, "点击我", Toast.LENGTH_SHORT ).show();
            }
        } );

    }

    @Override
    public void onClick(View v) {
     switch (v.getId()){
         case R.id.but1://透明
             ObjectAnimator alpha = ObjectAnimator.ofFloat( img, "alpha", new float[]{0.0f, 0.2f, 0.5f, 0.9f, 1.0f, 1.5f} );
             alpha.setDuration( 2000 );
             alpha.setRepeatCount( ObjectAnimator.RESTART );
             alpha.setRepeatCount( 1 );
             alpha.start();
             break;
         case R.id.but4://旋转
             ObjectAnimator rotationX = ObjectAnimator.ofFloat( img, "rotationX", new float[]{90f, 180f, 270f, 360f} );
             rotationX.setDuration( 2000 );
             rotationX.setRepeatCount( ObjectAnimator.RESTART );
             rotationX.setRepeatCount( 1 );
             rotationX.start();
             break;
         case R.id.but2://平移
             ObjectAnimator translationX = ObjectAnimator.ofFloat( img, "translationX", new float[]{10f, 20f, 30f, 50f, 70f, 85f} );
             translationX.setDuration( 2000 );
             translationX.setRepeatCount( ObjectAnimator.RESTART );
             translationX.setRepeatCount( 1 );
             translationX.start();
             break;
         case R.id.but3://缩放
             ObjectAnimator scalex = ObjectAnimator.ofFloat( img, "scaleX", new float[]{1f, 2f, 3f, 5f, 10f, 15f,1f} );
             scalex.setDuration( 2000 );
             scalex.setRepeatCount( ObjectAnimator.RESTART );
             scalex.setRepeatCount( 1 );
             scalex.start();
             break;
         case R.id.but5://组合
             AnimatorSet animatorSet = new AnimatorSet();
             ObjectAnimator rotationx = ObjectAnimator.ofFloat( img, "rotationX", new float[]{90f, 180f, 270f, 360f} );
             rotationx.setDuration( 2000 );
             ObjectAnimator translationx = ObjectAnimator.ofFloat( img, "translationX", new float[]{10f, 20f, 30f, 50f, 70f, 85f} );
             translationx.setDuration( 2000 );
             animatorSet.playTogether( rotationx,translationx );
             animatorSet.start();
             break;

     }
    }







、、、、、、、、、、、、、、、
已xml的形式的动画效果
  @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate( savedInstanceState );
        setContentView( R.layout.activity_main );
       
     
 
 Animator animator = AnimatorInflater.loadAnimator( this, R.animator.objectanimator );
        animator.setTarget( img );
        animator.start();
}xml文件(创建animator文件)
<?xml version="1.0" encoding="utf-8"?>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
    android:propertyName="rotationX"
    android:duration="3000"
    android:repeatCount="1"
    android:repeatMode="restart"
    android:startOffset="0"
    android:valueFrom="360.0"
    >

</objectAnimator>

 
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值