




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
【移动应用开发技术】Android如何实现旋转、平移、缩放和透明度渐变的补间动画
1.在新建项目的res目录中,创建一个名为anim的目录,并在该目录中创建实现旋转、平移、缩放和透明度渐变的动画资源文件。<?xml
version="1.0"
encoding="utf-8"?>
<set
xmlns:android="/apk/res/android">
<alpha
android:fromAlpha="1"
android:toAlpha="0"
android:fillAfter="true"
android:repeatMode="reverse"
android:repeatCount="1"
android:duration="2000"/>
</set><?xml
version="1.0"
encoding="utf-8"?>
<set
xmlns:android="/apk/res/android">
<rotate
android:interpolator="@android:anim/accelerate_interpolator"
android:fromDegrees="0"
android:toDegrees="720"
android:pivotX="50%"
android:pivotY="50%"
android:duration="2000"/>
<rotate
android:interpolator="@android:anim/accelerate_interpolator"
android:startOffset="2000"
android:fromDegrees="360"
android:toDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="2000"/>
</set><?xml
version="1.0"
encoding="utf-8"?>
<set
xmlns:android="/apk/res/android">
<scale
android:fromXScale="1"
android:interpolator="@android:anim/decelerate_interpolator"
android:fromYScale="1"
android:toXScale="2.0"
android:toYScale="2.0"
android:pivotX="50%"
android:pivotY="50%"
android:fillAfter="true"
android:repeatCount="1"
android:repeatMode="reverse"
android:duration="2000"/>
</set><?xml
version="1.0"
encoding="utf-8"?>
<set
xmlns:android="/apk/res/android">
<translate
android:fromXDelta="0"
android:toXDelta="860"
android:fromYDelta="0"
android:toYDelta="0"
android:fillAfter="true"
android:repeatMode="reverse"
android:repeatCount="1"
android:duration="2000"/>
</set>res/layout/main.xml:
[html]
view
plain
copy
<?xml
version="1.0"
encoding="utf-8"?>
<LinearLayout
xmlns:android="/apk/res/android"
xmlns:tools="/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/linearLayout1"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/linearLayout2"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button1"
android:text="旋转"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button2"
android:text="平移"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button3"
android:text="缩放"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button4"
android:text="透明度变化"/>
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView1"
android:src="@drawable/img1"/>
</LinearLayout>效果如图/upload/information/20200623/125/123456.jpg2.MainActivity:[java]
view
plain
copy
package
com.example.test;
import
android.app.Activity;
import
android.os.Bundle;
import
android.view.View;
import
android.view.View.OnClickListener;
import
android.view.animation.Animation;
import
android.view.animation.AnimationUtils;
import
android.widget.Button;
import
android.widget.ImageView;
public
class
MainActivity
extends
Activity
{
@Override
public
void
onCreate(Bundle
savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final
Animation
rotate=AnimationUtils.loadAnimation(this,
R.anim.anim_rotate);//获取旋转动画资源
final
Animation
translate=AnimationUtils.loadAnimation(this,
R.anim.anim_translate);//获取平移动画资源
final
Animation
scale=AnimationUtils.loadAnimation(this,
R.anim.anim_scale);//获取缩放动画资源
final
Animation
alpha=AnimationUtils.loadAnimation(this,
R.anim.anim_alpha);//获取透明度变化动画资源
//获取要应用动画效果的ImageView
final
ImageView
iv=(ImageView)findViewById(R.id.imageView1);
Button
button1=(Button)findViewById(R.id.button1);//获取"旋转"按钮
button1.setOnClickListener(new
OnClickListener()
{
@Override
public
void
onClick(View
arg0)
{
//播放旋转动画
iv.startAnimation(rotate);
}
});
Button
button2=(Button)findViewById(R.id.button2);//获取"平移"按钮
button2.setOnClickListener(new
OnClickListener()
{
@Override
public
void
onClick(View
arg0)
{
//播放平移动画
iv.startAnimation(translate);
}
});
Button
button3=(Button)findViewById(R.id.button3);//获取"缩放"按钮
button3.setOnClickListener(new
OnClickListener()
{
@Override
public
void
onClick(View
arg0)
{
//播放缩放动画
iv.startAnimation(scale);
}
});
Button
button4=(Button)findViewById(R.id.button4);//获取"透明度渐变"按钮
button4.setOnClickListener(new
OnClickListener()
{
@Override
public
void
onClick(
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 温州理工学院《居住建筑设计原理》2023-2024学年第二学期期末试卷
- 贵州城市职业学院《化工原理实验一》2023-2024学年第二学期期末试卷
- 南京工业职业技术大学《儿重发育保健护理》2023-2024学年第二学期期末试卷
- 河南质量工程职业学院《数字媒体后期制作》2023-2024学年第二学期期末试卷
- 山东现代学院《宝石合成与优化》2023-2024学年第二学期期末试卷
- 河南应用技术职业学院《建筑风格史》2023-2024学年第二学期期末试卷
- 四川音乐学院《ED器件与应用技术》2023-2024学年第二学期期末试卷
- 聊城大学《幼儿心理学》2023-2024学年第二学期期末试卷
- 黑龙江能源职业学院《有限元分析及应用》2023-2024学年第二学期期末试卷
- 2024-2025学年江西省“三新”协同教研体高三上学期12月份联考历史试卷
- 初中语文九年级下册阅读理解50篇附答案解析
- 《陶瓷造型工艺》课程标准
- 火电厂各指标指标解析(最新版)
- 病毒性脑炎患者的护理查房ppt课件
- TPU材料项目可行性研究报告写作参考范文
- 第二编 债权总论
- 试用期考核合格证明表
- 常见八种疾病
- 胶粘剂基础知识及产品详解(课堂PPT)
- 铁路总公司近期处理的七起突出质量问题的通报
- 常用洪水预报模型介绍
评论
0/150
提交评论