ObjectAnimator使用

在layout文件夹下建立animator文件夹存放xml文件,文件如下:



    
        
        
            
            
        

    

    
        
        
            
            
        

    

使用如下,通过获取AnimatorSet对象,来为target设置动画属性。

AnimatorSet obSet = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.together);
obSet.setTarget(mText);
obSet.start();

或者直接使用java组合使用ObjectAnimator

//组合使用ObjectAnimator
/*ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(mText, "scaleX", 1f, 2f);
ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(mText, "scaleY", 1f, 2f);
ObjectAnimator rotateAnimator = ObjectAnimator.ofFloat(mText, "rotation", 0f, 360f);
ObjectAnimator translateX = ObjectAnimator.ofFloat(mText, "translationX", 0f, 500f);
ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(mText, "alpha", 1f, 0f );
AnimatorSet mset = new AnimatorSet();
mset.play(scaleXAnimator).with(scaleYAnimator).with(rotateAnimator).with(translateX).before(alphaAnimator);
mset.setDuration(3000);
mset.addListener(new AnimatorListenerAdapter() {
    @Override
    public void onAnimationStart(Animator animation) {
        Toast.makeText(MainActivity.this, "Hello ObjectAnimation", Toast.LENGTH_SHORT).show();
    }
});*/

你可能感兴趣的:(ObjectAnimator使用)