软件编程
位置:首页>> 软件编程>> Android编程>> 浅谈Android中视图动画的属性与使用

浅谈Android中视图动画的属性与使用

作者:墨革  发布时间:2023-04-15 22:41:12 

标签:android,视图,动画

简介

Android动画主要包括视图动画和属性动画,视图动画包括Tween动画和Frame动画,Tween动画又包括渐变动画、平移动画、缩放动画、旋转动画。

Tween动画的基本属性

      目标 View;

      时常 duration;

      开始状态 fromXXX;

      结束动画 toXXX;

      开始时间 startOffset;

      重复次数 repeatCount;

      时间轴 interpolator(插值器)。

代码示例

xml实现


<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0"
android:fromYDelta="0"
android:toXDelta="100%"
android:toYDelta="0"
android:fillAfter="true"
android:duration="3000">
</translate>

在代码中调用


Animation translate = AnimationUtils.loadAnimation(context,R.anim.translate);
imageView.startAnimation(translate);

补充:

1.对于缩放和旋转动画,有一个pivotX或者pivotY,表示的是缩放或旋转的中心点。

对应的属性值有三种写法。

     · 数值 50 表示当前控件的左上角加上50px;

     · 百分数 50% 表示当前控件的50%;

     · 百分数p 50%p 表示父控件的50%。

2.在一个动画集合里,可以通过设置stratOffset属性,来实现多个动画并行和串行的效果。

Frame动画

Frame动画的配置文件放在drawable目录下


<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/image1" android:duration="50"/>
<item android:drawable="@drawable/image2" android:duration="50"/>
<item android:drawable="@drawable/image3" android:duration="50"/>
</animation-list>

// 需要先设置成背景
imageView.setBackgroundResource(R.drawable.frame_anim);
AnimationDrawable frameAnimation = (AnimationDrawable) imageView.getBackground();
frameAnimation.start();

总结

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com