属性动画四种属性的点击实现

创建控件



   


   
主类中的JAVA码

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    /**
     * 位移
     */
    private Button bt_tranla;
    /**
     * 旋转
     */
    private Button mBtRotation;
    /**
     * 透明
     */
    private Button mBtAlpha;
    /**
     * 缩放
     */
    private Button mBtScale;
    /**
     * 位移
     */
    private Button mBtTranla;
    private ImageView mImageView;

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


    private void initView() {
        bt_tranla = (Button) findViewById(R.id.bt_tranla);
        bt_tranla.setOnClickListener(this);
        mBtRotation = (Button) findViewById(R.id.bt_rotation);
        mBtRotation.setOnClickListener(this);
        mBtAlpha = (Button) findViewById(R.id.bt_alpha);
        mBtAlpha.setOnClickListener(this);
        mBtScale = (Button) findViewById(R.id.bt_scale);
        mBtScale.setOnClickListener(this);
        mBtTranla = (Button) findViewById(R.id.bt_tranla);
        mBtTranla.setOnClickListener(this);
        mImageView = (ImageView) findViewById(R.id.imageView);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {

            case R.id.bt_tranla:
                ObjectAnimator object_tranla = ObjectAnimator.ofFloat(bt_tranla, "translationX", 0, 10, 20, 50, 300);
                object_tranla.setDuration(5000);
                object_tranla.setRepeatCount(ObjectAnimator.INFINITE);
                object_tranla.start();
                break;
            case R.id.bt_rotation:
                ObjectAnimator object_rotation = ObjectAnimator.ofFloat(mImageView, "rotation", 0, 10, 20, 50, 300);
                object_rotation.setDuration(5000);
                object_rotation.start();

                break;
            case R.id.bt_alpha:
                ObjectAnimator object_alpha = ObjectAnimator.ofFloat(mImageView, "alpha", 1.0f, 0.9f, 0.6f,0);
                object_alpha.setDuration(5000);
                object_alpha.start();

                break;
            case R.id.bt_scale:
                ObjectAnimator object_scale = ObjectAnimator.ofFloat(mImageView, "scaleX", 1,0);
                object_scale.setDuration(5000);
                object_scale.start();
                break;
        }
    }
}

 

 

 

 

你可能感兴趣的:(属性动画四种属性的点击实现)