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

创建控件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.myapplication.MainActivity">
   <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content">


   <Button
       android:id="@+id/bt_tranla"
       android:onClick="translation"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="位移"
       />
   <Button
       android:id="@+id/bt_rotation"
       android:onClick="rotation"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="旋转"
       />
   <Button
       android:id="@+id/bt_alpha"
       android:onClick="alpha"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="透明"
       />
   <Button
       android:id="@+id/bt_scale"
       android:onClick="scale"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="缩放"
       />
   </LinearLayout>
 <ImageView

     android:id="@+id/imageView"
     android:layout_width="100dp"
     android:layout_height="150dp"
     android:src="@mipmap/ic_launcher"

     />
</LinearLayout>
主类中的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;
        }
    }
}

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值