PropertyAnimation属性动画

属性动画跟补间动画实现一样简单

<?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="yangxuexue.bwie.com.propertyanimation.MainActivity">

    <Button
        android:onClick="apale"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="渐变"/>
    <Button
        android:onClick="translation"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="移动"/>
    <Button
        android:onClick="rotation"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="旋转"/>
    <Button
        android:onClick="scale"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="缩放"/>
    <Button
        android:onClick="set"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="组合"/>
    <ImageView
        android:id="@+id/imageview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@mipmap/ic_launcher"/>
</LinearLayout>
public class MainActivity extends AppCompatActivity {
    private ImageView imageView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        imageView = (ImageView) findViewById(R.id.imageview);
    }

    public void apale(View v) {
        //透明度起始为1,结束时为0
        ObjectAnimator animator = ObjectAnimator.ofFloat(imageView, "alpha", 1f, 0f,1f);
        animator.setDuration(1000);//时间1s
        animator.start();
    }

    //旋转
    public void rotation(View v) {
        ObjectAnimator animator = ObjectAnimator.ofFloat(imageView, "rotation", 0f, 360f, 0f);
        animator.setDuration(2000);
        animator.start();
    }

    //缩放
    public void scale(View v) {
        ObjectAnimator animator = ObjectAnimator.ofFloat(imageView, "scaleX", 1f, 2f, 1f);
        animator.setDuration(2000);
        animator.start();
    }

    //移动
    public void translation(View v) {
        ObjectAnimator animator = ObjectAnimator.ofFloat(imageView, "translationX", 0f, -300f, 0f);
        animator.setDuration(2000);
        animator.start();
    }

    //组合
    public void set(View v) {
//沿x轴放大
        ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(imageView, "scaleX", 1f, 2f, 1f);
//沿y轴放大
        ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(imageView, "scaleY", 1f, 2f, 1f);
//移动
        ObjectAnimator translationXAnimator = ObjectAnimator.ofFloat(imageView, "translationX", 0f, 200f, 0f);
//透明动画
        ObjectAnimator animator = ObjectAnimator.ofFloat(imageView, "alpha", 1f, 0f, 1f);
        AnimatorSet set = new AnimatorSet();
//同时沿X,Y轴放大,且改变透明度,然后移动
        set.play(scaleXAnimator).with(scaleYAnimator).with(animator).before(translationXAnimator);
//都设置3s,也可以为每个单独设置
        set.setDuration(3000);
        set.start();


    }
}

这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值