Android 动画之ScaleAnimation应用详解
时间:2023-05-08 19:36:28
android中提供了4中动画:
AlphaAnimation 透明度动画效果
ScaleAnimation 缩放动画效果
TranslateAnimation 位移动画效果
RotateAnimation 旋转动画效果
本节讲解ScaleAnimation 动画,
ScaleAnimation(float fromX, float toX, float fromY, float toY,int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
参数说明:
float fromX 动画起始时 X坐标上的伸缩尺寸
float toX 动画结束时 X坐标上的伸缩尺寸
float fromY 动画起始时Y坐标上的伸缩尺寸
float toY 动画结束时Y坐标上的伸缩尺寸
int pivotXType 动画在X轴相对于物件位置类型
float pivotXValue 动画相对于物件的X坐标的开始位置
int pivotYType 动画在Y轴相对于物件位置类型
float pivotYValue 动画相对于物件的Y坐标的开始位置
代码:
public class MainActivity extends Activity {
ImageView image;
Button start;
Button cancel;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
image = (ImageView) findViewById(R.id.main_img);
start = (Button) findViewById(R.id.main_start);
cancel = (Button) findViewById(R.id.main_cancel);
/** 设置缩放动画 */
final ScaleAnimation animation =new ScaleAnimation(0.0f, 1.4f, 0.0f, 1.4f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
animation.setDuration(2000);//设置动画持续时间
/** 常用方法 */
//animation.setRepeatCount(int repeatCount);//设置重复次数
//animation.setFillAfter(boolean);//动画执行完后是否停留在执行完的状态
//animation.setStartOffset(long startOffset);//执行前的等待时间
start.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
image.setAnimation(animation);
/** 开始动画 */
animation.startNow();
}
});
cancel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
/** 结束动画 */
animation.cancel();
}
});
}
}
效果:
标签:Android动画,ScaleAnimation
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
常用类之TCP连接类-socket编程
2021-08-03 16:46:25
Android自定义wheelview实现滚动日期选择器
2021-11-22 16:04:19
![](https://img.aspxhome.com/file/2023/6/129036_0s.png)
android自定义按钮示例(重写imagebutton控件实现图片按钮)
2021-06-13 07:55:19
MyBatis快速入门(简明浅析易懂)
2022-05-25 23:08:55
![](https://img.aspxhome.com/file/2023/9/128839_0s.png)
解决android studio 打开java文件 内容全变了的问题
2022-03-18 19:31:44
![](https://img.aspxhome.com/file/2023/2/96032_0s.jpg)
Android实现图片加载进度提示
2022-09-11 17:54:44
![](https://img.aspxhome.com/file/2023/4/118934_0s.jpg)
在IDEA中配置tomcat并创建tomcat项目的图文教程
2023-08-11 11:33:59
![](https://img.aspxhome.com/file/2023/4/78934_0s.png)
Java内存溢出案例模拟和原理分析过程
2023-04-09 07:27:48
![](https://img.aspxhome.com/file/2023/3/125573_0s.png)
Java8 中的ParallelStream
2022-09-07 19:00:23
![](https://img.aspxhome.com/file/2023/4/87224_0s.png)
Maven打包jar生成javadoc文件和source文件代码实例
2021-08-22 21:56:52
Android开发实现的标准体重计算器功能示例
2023-01-19 02:56:48
![](https://img.aspxhome.com/file/2023/0/139280_0s.jpg)
C# 对XML基本操作代码总结
2022-08-21 16:09:09
ListView 分页加载更新实例分享
2021-09-05 06:53:11
![](https://img.aspxhome.com/file/2023/8/91648_0s.png)
Java之 TreeSet的详细使用说明
2021-08-22 14:52:22
![](https://img.aspxhome.com/file/2023/8/77078_0s.jpg)
在 C# 中使用 插值字符串
2023-06-23 07:09:50
Java读取TXT文件内容的方法
2023-11-23 22:33:41
C#利用反射来判断对象是否包含某个属性的实现方法
2023-02-26 06:57:52
Android实现图片反转、翻转、旋转、放大和缩小
2022-07-04 20:15:34
Android GestureDetector用户手势检测实例讲解
2022-12-28 17:24:46
![](https://img.aspxhome.com/file/2023/2/88702_0s.png)
分析Android Choreographer源码
2022-09-04 07:25:12
![](https://img.aspxhome.com/file/2023/4/105984_0s.jpg)