Android 中 Tweened animation的实例详解
作者:zhangqijie001 时间:2022-12-12 15:28:06
Android 中 Tweened animation的实例详解
Tweened animation有四种类型,下面主要介绍Scale类型。
运行效果如下:
Android SDK提供了2种方法:直接从XML资源中读取Animation,使用Animation子类的构造函数来初始化Animation对象,第二种方法在看了Android SDK中各个类的说明就知道如何使用了,下面简要说明从XML资源中读取Animation。XML资源中的动画文件animation.xml内容为:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:fromXScale="0.0"
android:toXScale="1.4"
android:fromYScale="0.0"
android:toYScale="1.4"
android:pivotX="50%"
android:pivotY="50%"
android:fillAfter="false"
android:startOffset="3000"
android:duration="3000"
android:repeatCount="4"/>
</set>
主文件ScaleAnimation.java内容为:
package com.android.animation;
import android.app.Activity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
public class TestAnimation extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView imageView = (ImageView) findViewById(R.id.imageview);
Animation animation = AnimationUtils.loadAnimation(this, R.anim.animation);
imageView.startAnimation(animation);
}
}
程序很容易看懂,主要为了说明伸缩动画效果而没有增加复杂性。值得说明的是,本人在测试阶段,错误的认为不需要布局文件,把行setContentView(R.layout.main);去掉,导致程序运行一直出错。其实动画也需要首先把布局文件加载到Activity里面,然后对布局里面的控件增加动画。
如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
来源:http://blog.csdn.net/zhangqijie001/article/details/5833098
标签:Android,Tweened,animation
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
JavaWeb开发使用Cookie创建-获取-持久化、自动登录、购物记录、作用路径
2022-01-11 10:37:28
![](https://img.aspxhome.com/file/2023/2/64902_0s.png)
Mybatis返回int或者Integer类型报错的解决办法
2023-08-09 02:41:14
Spring bean配置单例或多例模式方式
2023-01-18 04:03:57
![](https://img.aspxhome.com/file/2023/3/63643_0s.jpg)
如何利用Spring把元素解析成BeanDefinition对象
2023-11-23 05:17:16
![](https://img.aspxhome.com/file/2023/9/59939_0s.png)
Android Studio实现简易计算器(表格布局TableLayout)
2021-11-17 23:20:07
![](https://img.aspxhome.com/file/2023/4/98624_0s.jpg)
Android基于Intent实现Activity之间数据传递的方法
2022-08-01 16:34:04
浅谈Java多线程编程中Boolean常量的同步问题
2021-06-20 16:36:26
Android中执行java命令的方法及java代码执行并解析shell命令
2022-08-27 15:45:13
c#实现将pdf转文本的示例分享
2023-07-19 14:54:23
springboot @WebFilter注解过滤器的实现
2023-07-06 11:14:54
Android中Canvas的常用方法总结
2021-11-25 03:00:28
![](https://img.aspxhome.com/file/2023/1/111721_0s.png)
Android 友盟第三方登录与分享的实现代码
2022-11-12 22:27:48
![](https://img.aspxhome.com/file/2023/6/114376_0s.png)
Java如何将二维数组转化为一维数组
2022-11-18 12:23:18
![](https://img.aspxhome.com/file/2023/7/125617_0s.png)
深入了解Java虚拟机栈以及内存模型
2022-02-17 13:37:50
![](https://img.aspxhome.com/file/2023/0/112420_0s.jpg)
Java 分割字符串详解及实例代码
2023-11-29 13:18:42
Android OnCreate()中获取控件高度与宽度两种方法详解
2022-08-03 15:09:40
Java Web项目中解决中文乱码方法总结(三种最新方法)
2023-07-18 18:13:22
![](https://img.aspxhome.com/file/2023/7/65337_0s.png)
spring boot使用拦截器修改请求URL域名 换 IP 访问的方法
2022-08-21 20:15:53
Java泛型变量如何添加约束
2021-06-02 23:12:06
JAVA常用API总结与说明
2023-05-19 08:17:17