属性动画的平移加旋转

我对属性动画的理解不深刻,随意写一下

首先写一个textview
"@+id/tv"
        android:layout_width="100dp"
        android:layout_height="50dp"
        android:background="#ff3360"
        android:gravity="center"
        android:text="呵呵" />

去mainactivity去让这个textview动起来

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private TextView mTv;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        //设置从上往下的平移效果
        ObjectAnimator transkationY = ObjectAnimator.ofFloat(mTv,"translationY", -10, 1100f);
        ObjectAnimator transkationX = ObjectAnimator.ofFloat(mTv,"translationX", 0, 0f);
        //设置旋转的效果
        ObjectAnimator ra = ObjectAnimator.ofFloat(mTv,"rotation", 0f, 360f);

        AnimatorSet animatorSet = new AnimatorSet();
        //将动画添加
        animatorSet.play(transkationY).with(transkationX).with(ra);
        animatorSet.setDuration(3000);
        ra.setDuration(3000);
        ra.start();
        animatorSet.start();
        //动画的监听
        animatorSet.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animator) {

            }

            @Override
            public void onAnimationEnd(Animator animator) {
                //动画结束跳转
                Intent intent = new Intent(MainActivity.this, Main2Activity.class);
                startActivity(intent);
            }

            @Override
            public void onAnimationCancel(Animator animator) {

            }

            @Override
            public void onAnimationRepeat(Animator animator) {

            }
        });

    }

这是最简单的平移加旋转动画

你可能感兴趣的:(属性动画的平移加旋转)