简单的属性动画的实现

配置静态属性

<?xml version="1.0" encoding="utf-8"?>

import android.animation.Animator;
import android.animation.AnimatorInflater;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.Toast;
**
**
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private Button alpha_bt;
private Button translationY_bt;
private Button scaleX_bt;
private Button rotationY_bt;
private Button AnimatorSet_bt;
private ImageButton animation_iv;
**
**
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
//实现静态的旋转属性
Animator animator= AnimatorInflater.loadAnimator(this,R.animator.objectdonghua);
animator.setTarget(animation_iv);
animator.start();
}
private void initView() {
alpha_bt = (Button) findViewById(R.id.alpha_bt);
translationY_bt = (Button) findViewById(R.id.translationY_bt);
scaleX_bt = (Button) findViewById(R.id.scaleX_bt);
rotationY_bt = (Button) findViewById(R.id.rotationY_bt);
AnimatorSet_bt = (Button) findViewById(R.id.AnimatorSet_bt);
animation_iv = (ImageButton) findViewById(R.id.animation_iv);
alpha_bt.setOnClickListener(this);
translationY_bt.setOnClickListener(this);
scaleX_bt.setOnClickListener(this);
rotationY_bt.setOnClickListener(this);
AnimatorSet_bt.setOnClickListener(this);
animation_iv.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.alpha_bt:
//实现动态的透明属性
ObjectAnimator alpha = ObjectAnimator.ofFloat(animation_iv, “alpha”, new float[]{0.1f, 0.3f, 0.6f, 1.0f});
alpha.setDuration(2000);
alpha.setRepeatMode(ObjectAnimator.RESTART);
alpha.setRepeatCount(1);
alpha.start();
break;
case R.id.translationY_bt:
//实现动态的平移属性
ObjectAnimator translation = ObjectAnimator.ofFloat(animation_iv, “translationY”, new float[]{90f, 180f, 60f, 360f});
translation.setDuration(2000);
translation.setRepeatMode(ObjectAnimator.RESTART);
translation.setRepeatCount(1);
translation.start();
break;
case R.id.scaleX_bt:
//实现动态的缩放属性
ObjectAnimator scaleX = ObjectAnimator.ofFloat(animation_iv, “scaleX”, new float[]{1f, 3f, 6f, 10f});
scaleX.setDuration(2000);
scaleX.setRepeatMode(ObjectAnimator.RESTART);
scaleX.setRepeatCount(1);
scaleX.start();
break;
case R.id.rotationY_bt:
//实现动态的旋转属性
ObjectAnimator rotationY = ObjectAnimator.ofFloat(animation_iv, “rotationY”, new float[]{0f, 360f});
rotationY.setDuration(2000);
rotationY.setRepeatMode(ObjectAnimator.RESTART);
rotationY.setRepeatCount(1);
rotationY.start();
break;
case R.id.AnimatorSet_bt:
//实现动态的属性集合
AnimatorSet animatorSet=new AnimatorSet();
ObjectAnimator alpha1 = ObjectAnimator.ofFloat(animation_iv, “alpha”, new float[]{0.1f, 0.3f, 0.6f, 1.0f});
alpha1.setDuration(2000);
ObjectAnimator translation1 = ObjectAnimator.ofFloat(animation_iv, “translationY”, new float[]{90f, 180f, 60f, 360f});
translation1.setDuration(2000);
ObjectAnimator scaleX1 = ObjectAnimator.ofFloat(animation_iv, “scaleX”, new float[]{1f, 3f, 6f, 10f});
scaleX1.setDuration(2000);
ObjectAnimator rotationY1 = ObjectAnimator.ofFloat(animation_iv, “rotationY”, new float[]{0f, 360f});
rotationY1.setDuration(2000);
//animatorSet.playSequentially(alpha1,translation1,scaleX1,rotationY1);
animatorSet.playTogether(alpha1,translation1,scaleX1,rotationY1);
animatorSet.start();
break;
case R.id.animation_iv:
//实现图片的点击
Toast.makeText(MainActivity.this,“图片被点击了。。。”,Toast.LENGTH_SHORT).show();
break;
}
}
}

<?xml version="1.0" encoding="utf-8"?>


<Button
    android:id="@+id/alpha_bt"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="alpha"/>

<Button
    android:id="@+id/translationY_bt"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="translationY"/>

<Button
    android:id="@+id/scaleX_bt"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="scaleX"/>

<Button
    android:id="@+id/rotationY_bt"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="rotationY"/>

<Button
    android:id="@+id/AnimatorSet_bt"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="AnimatorSet"/>

<ImageButton
    android:onClick="yyyy"
    android:id="@+id/animation_iv"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:src="@mipmap/ic_launcher"
    android:background="@null"/>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值