Android开发学习之Animation之Android帧动画解析
16lz
2021-12-04
今天给大家分享的是Android中的动画,在Android中系统为我们提供了四种动画效果,分别是:缩放、平移、旋转、渐变。下面我们通过一个简单的例子来了解Android中的动画机制。这里我们主要用到的类有ScaleAnimation、TranslateAnimation、RotateAnimation、AlphaAnimation,分别对应上面的四种动画效果。代码实现如下:
package com.Android.Animation;import android.os.Bundle;import android.app.Activity;import android.view.Menu;import android.view.View;import android.view.View.OnClickListener;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 {Button BtnScale,BtnMove,BtnRoate,BtnAlpha;ImageView iv;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);BtnScale=(Button)findViewById(R.id.BtnScale);BtnScale.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View arg0) {Animation Ani_Scale=new ScaleAnimation(0f, 1f, 0f, 1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);Ani_Scale.setDuration(3000);iv.startAnimation(Ani_Scale);}});BtnMove=(Button)findViewById(R.id.BtnMove);BtnMove.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View arg0) {Animation Ani_Trans = new TranslateAnimation(10,100,10,100);Ani_Trans.setDuration(3000);iv.startAnimation(Ani_Trans);}});BtnRoate=(Button)findViewById(R.id.BtnRoate);BtnRoate.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View arg0) {Animation Ani_Rotate = new RotateAnimation(0f, -360f,Animation.RELATIVE_TO_SELF, 0.5f,Animation.RELATIVE_TO_SELF, 0.5f);Ani_Rotate.setDuration(3000);iv.startAnimation(Ani_Rotate);}});BtnAlpha=(Button)findViewById(R.id.BtnAlpha);BtnAlpha.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View arg0) {Animation Ani_Alpha = new AlphaAnimation(0.1f, 1.0f);Ani_Alpha.setDuration(3000); iv.startAnimation(Ani_Alpha);}});iv=(ImageView)findViewById(R.id.ImageView);}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}}
更多相关文章
- Android实现导航菜单左右滑动效果
- Android移动view动画问题(让移动更平滑)
- 炫酷的MaterialDesign Ripple水波纹动画效果
- TextView中的文字添加阴影效果及Style的使用
- Android(安卓)的 Tweened animation
- android UI进阶之弹窗的使用(2)--实现通讯录的弹窗效果
- Android制作并替换系统开机动画bootanimation.zip(需root)
- Android实现左右滑动指引效果
- Android(安卓)UI开发第八篇——ViewFlipper 左右滑动效果