Android中补间动画1----Animation的基本使用代码实现(平移,缩放,渐变,旋转)
来源:互联网 发布:剪切的数据怎么恢复 编辑:程序博客网 时间:2024/05/22 04:56
效果图:
MainActivity
package com.zhh.android;import android.app.Activity;import android.content.Intent;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.view.animation.AlphaAnimation;import android.view.animation.Animation;import android.view.animation.RotateAnimation;import android.view.animation.ScaleAnimation;import android.view.animation.TranslateAnimation;import android.widget.Button;import android.widget.ImageView;public class MainActivity extends Activity {// 缩放 private Button btnScale;// 旋转 private Button btnRotate;// 渐变 private Button btnAlpha;// 平移动画 private Button btnTranslation; private ImageView ivLauncher; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initView(); myOnclick(); } /** * 初始化控件 */ private void initView() { btnScale = (Button)findViewById(R.id.btnScale); btnRotate = (Button)findViewById(R.id.btnRotate); ivLauncher = (ImageView)findViewById(R.id.ivLauncher); btnAlpha = (Button)findViewById(R.id.btnAlpha); btnTranslation = (Button)findViewById(R.id.btnTranslation); } /** * 点击事件 */ private void myOnclick() {// 缩放 btnScale.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { setScaleAnimation(); } });// 旋转 btnRotate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { setRotateAnimation(); } });// 渐变 btnAlpha.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { setAlphaAnimation(); } });// 平移 btnTranslation.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { setTranslationAnimation(); } });// 跳转到下一页 ivLauncher.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(MainActivity.this,Main2Activity.class)); } }); } /** * 缩放动画 */ private void setScaleAnimation(){// 效果:宽度从0.5到1.5,高度从0.0到1.0,缩放的圆心为顶部中心点,延迟1s开始,持续2s,最终还原// 1创建动画对象// Animation.ABSOLUTE绝对的// ScaleAnimation scaleAnimation = new ScaleAnimation(0.5f,1.5f,0.0f,1.0f,// Animation.ABSOLUTE,ivLauncher.getWidth()/2,Animation.ABSOLUTE,0f);// Animation.RELATIVE_TO_SELF相对自己 ScaleAnimation scaleAnimation = new ScaleAnimation(0.5f,1.5f,0.0f,1.0f, Animation.RELATIVE_TO_SELF,0.5f, Animation.RELATIVE_TO_SELF,0f);// 2设置// 延迟一秒开始 scaleAnimation.setStartOffset(1000);// 持续两秒 scaleAnimation.setDuration(2000);// 最终还原 scaleAnimation.setFillBefore(true);// 3启动动画 ivLauncher.startAnimation(scaleAnimation); } /** * 旋转动画 */ private void setRotateAnimation(){// 效果以图片中心点为中心,从负90度到正90度,持续5s// 1创建动画对象 RotateAnimation rotateAnimation = new RotateAnimation(-90,90,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);// 2设置 rotateAnimation.setDuration(5000);// 3启动动画 ivLauncher.startAnimation(rotateAnimation); } /** * 渐变动画 */ private void setAlphaAnimation(){// 效果:从完全透明,到完全不透明// 1创建动画对象 AlphaAnimation alphaAnimation =new AlphaAnimation(0f,1f);// 2设置 alphaAnimation.setDuration(5000);// 3启动动画 ivLauncher.startAnimation(alphaAnimation); } /** * 平移动画 */ private void setTranslationAnimation(){// 效果,向右移动一个自己的宽度,向下移动一个自己的高度,持续2秒// 1创建动画对象 Animation.RELATIVE_TO_SELF,0f, Animation.RELATIVE_TO_SELF,平移的是左上角的坐标 TranslateAnimation translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF,0f, Animation.RELATIVE_TO_SELF,1f, Animation.RELATIVE_TO_SELF,0f, Animation.RELATIVE_TO_SELF,1f);// 2设置 translateAnimation.setDuration(2000);// 3启动动画 ivLauncher.startAnimation(translateAnimation); }}activity_main.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.zhh.android.MainActivity" android:orientation="vertical" > <Button android:id="@+id/btnScale" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="缩放动画" android:textSize="30dp" /> <Button android:id="@+id/btnRotate" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="旋转动画" android:textSize="30dp" /> <Button android:id="@+id/btnAlpha" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="渐变动画" android:textSize="30dp" /> <Button android:id="@+id/btnTranslation" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="平移动画" android:textSize="30dp" /> <ImageView android:id="@+id/ivLauncher" android:layout_width="wrap_content" android:layout_height="200dp" android:src="@mipmap/cyl" android:layout_gravity="center_horizontal" /></LinearLayout>参考视频:
http://www.gulixueyuan.com/course/112/task/1793/show#
源码下载:
阅读全文
0 0
- Android中补间动画1----Animation的基本使用代码实现(平移,缩放,渐变,旋转)
- Android中属性动画1----ObjectAnimator的基本使用(平移,缩放,渐变,旋转)
- 动画效果之渐变、缩放、平移、旋转<代码实现>
- 动画效果之渐变、缩放、平移、旋转<代码实现>
- Android 实现属性动画平移,旋转,缩放,渐变 《H》
- Android开发--图形图像与动画(二)--Animation实现图像的 渐变、缩放、位移、旋转
- Android 补间动画(动画列表,平移,旋转,缩放,渐变,动画集合)
- 讲述属性动画的使用 —使用动画旋转、平移、渐变和缩放
- 【Android开发】动画范例2-旋转、平移、缩放和透明度渐变的补间动画
- 旋转平移,缩放,透明度渐变的补间动画
- 旋转、平移、缩放和透明度渐变的补间动画
- Android 旋转、平移、缩放和透明度渐变的补间动画
- android动画(平移,旋转,缩放,透明度)
- android动画,旋转,渐变,缩放
- 【Android动画】之Tween动画 (渐变、缩放、位移、旋转)代码中的实现
- css3平移、旋转、倾斜、缩放、动画效果的实现
- android游戏开发5-10 补间动画 透明度渐变 旋转 缩放 平移
- Android 通过Animate硬编码实现简单的平移、旋转、缩放及透明度动画过程
- Somethings about the Process scheduler in Linux
- 关于unity自带延时函数
- 数据结构实验之图论二:图的深度遍历
- HTTP中Get与Post的区别
- Android 系统权限使用详解
- Android中补间动画1----Animation的基本使用代码实现(平移,缩放,渐变,旋转)
- UE4蓝图节点翻译---Get Components by Tag
- JS——判断数组
- 考试题(进制问题)
- ES7之async/await异步方案
- idea使用SVN
- 基于框架开发的办公软件实例
- 攻击手段
- CentOS 7 安装FTP服务器(vsftpd)