android 动画

Android  /  houtizong 发布于 3年前   81

android的动画有两种  tween动画和Frame动画

 

tween动画;,透明度,缩放,旋转,平移效果

 

Animation   动画

AlphaAnimation 渐变透明度

RotateAnimation 画面旋转

ScaleAnimation 渐变尺寸缩放

TranslateAnimation 位置移动

AnimationSet  动画集

 

使用方式

在res文件下创建anim文件;

 

1,透明度效果

aniation_xml
<?xml version="1.0" encoding="utf-8"?><alpha xmlns:android="http://schemas.android.com/apk/res/android"    android:fromAlpha="0"    android:toAlpha="1"    android:duration="1000"    ></alpha>

 

操作透明度xml的类

public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);ImageView images = (ImageView) this.findViewById(R.id.images);// 透明度//加载动画的文件Animation animation = AnimationUtils.loadAnimation(this,R.anim.aniation_xml);        //设置执行后不变animation.setFillAfter(true);//启动动画images.startAnimation(animation);}}

 

2,平移动画

 

<?xml version="1.0" encoding="utf-8"?><translate xmlns:android="http://schemas.android.com/apk/res/android"     android:fromXDelta="10%"    android:fromYDelta="10%"    android:toXDelta="50%p"    android:toYDelta="50%p"    android:duration="5000"    ></translate>

 

public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);ImageView images = (ImageView) this.findViewById(R.id.images);//加载动画的文件 //平移 Animation animation =AnimationUtils.loadAnimation(this, R.anim.translate_xml);        //设置执行后不变animation.setFillAfter(true);//启动动画images.startAnimation(animation);

 

 

3,缩放动画   操作与上面类似

<?xml version="1.0" encoding="utf-8"?><scale xmlns:android="http://schemas.android.com/apk/res/android"    android:duration="5000"    android:fromXScale="1.0"    android:fromYScale="1.0"    android:pivotX="50%"    android:pivotY="50%"    android:toXScale="1.4"    android:toYScale="0.6" ></scale>

 

 

4,旋转动画

<?xml version="1.0" encoding="utf-8"?><rotate xmlns:android="http://schemas.android.com/apk/res/android"     android:fromDegrees="0"    android:toDegrees="360"    android:pivotX="50%"    android:pivotY="50%"    android:duration="5000"     >    </rotate>

 

 

5,Frame动画  相当于GIF图片

在放图片的文件下创建文件存放资源 frame

 

<?xml version="1.0" encoding="utf-8"?><animation-list xmlns:android="http://schemas.android.com/apk/res/android" >       <item android:drawable="@drawable/ic_launcher" android:duration="1000" />     <item android:drawable="@drawable/mainback" android:duration="2000" /></animation-list>

 

duration 设置时间

 

animation-list 里面存放图片

 

操作Frame动画

@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);ImageView images = (ImageView) this.findViewById(R.id.images);           //获得资源文件 images.setBackgroundResource(R.drawable.frame); //设置背景图片 AnimationDrawable animation=(AnimationDrawable)images.getBackground(); animation.start();//启动

 

 

 

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!

留言需要登陆哦

技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成

网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];

      订阅博客周刊 去订阅

文章归档

文章标签

友情链接

Auther ·HouTiZong
侯体宗的博客
© 2020 zongscan.com
版权所有ICP证 : 粤ICP备20027696号
PHP交流群 也可以扫右边的二维码
侯体宗的博客