propertyAnimator(属性动画)之objectanimator(动画执行类)

1:获取一张图片,用系统图片也可以

<ImageView
    android:id="@+id/image"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:src="@mipmap/ic_launcher"/>
<Button
    android:id="@+id/bt_begin"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:text="开始动画"/>
2:接下来就在代码中实现属性动画

public class MainActivity extends AppCompatActivity {
    private ImageView image;
    private Button bt_begin;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        image= (ImageView) findViewById(R.id.image);
        bt_begin= (Button) findViewById(R.id.bt_begin);
        //1:直接定义实现属性动画
        /*bt_begin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ObjectAnimator.ofFloat(image,"rotationY",0.0f,60.0f).setDuration(3000).start();
            }
        });*/
        //自定义实现属性动画
        /*bt_begin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ObjectAnimator animator = ObjectAnimator.ofFloat(image, "lianglei", 1.0f, 0.5f).setDuration(3000);
                animator.start();
                animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public void onAnimationUpdate(ValueAnimator animation) {
                        float animatedValue = (float) animation.getAnimatedValue();
                        image.setAlpha(animatedValue);
                        image.setScaleX(animatedValue);
                        image.setScaleY(animatedValue);
                    }
                });
            }
        });*/
        //3: 通过PropertyValuesHolder实现属性动画
        bt_begin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f, 0.5f);
                PropertyValuesHolder rotationX = PropertyValuesHolder.ofFloat("rotationX", 0.0f, 30.0f);
                ObjectAnimator.ofPropertyValuesHolder(image,alpha,rotationX).setDuration(3000).start();
            }
        });
    }
}
3:推荐博客   http://blog.csdn.net/lmj623565791/article/details/38067475/

你可能感兴趣的:(propertyAnimator(属性动画)之objectanimator(动画执行类))