Android动画——Tween动画之Scale

创建资源文件

在res文件夹下创建anim文件夹,在anim中新建一个资源文件,文件名随意
这里写图片描述

编写代码

<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXScale="1.0"
    android:toXScale="2.0"
    android:fromYScale="1.0"
    android:toYScale="2.0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:fillAfter="false"
    android:duration="3000"
    android:repeatCount="10"/>

属性介绍

android:fromXScale  动画开始时X轴倍数
android:toXScale    动画结束时X轴倍数
android:fromYScale  动画开始时Y轴倍数
android:toYScale    动画结束时Y轴倍数
android:pivotX      缩放中心点的X轴位置
android:pivotY      缩放中心点的Y轴位置
android:fillAfter   动画结束后停在最后一帧
android:duration    每次动画持续时间
android:repeatCount 动画重复次数

初始化动画

imageView = (ImageView) rootView.findViewById(R.id.imageview);
animation = AnimationUtils.loadAnimation(getContext(), R.anim.scale);

开始动画

imageView.startAnimation(animation);

结束动画

animation.cancel();
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章