今天给大家分享的是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;}}

更多相关文章

  1. Android实现导航菜单左右滑动效果
  2. Android移动view动画问题(让移动更平滑)
  3. 炫酷的MaterialDesign Ripple水波纹动画效果
  4. TextView中的文字添加阴影效果及Style的使用
  5. Android(安卓)的 Tweened animation
  6. android UI进阶之弹窗的使用(2)--实现通讯录的弹窗效果
  7. Android制作并替换系统开机动画bootanimation.zip(需root)
  8. Android实现左右滑动指引效果
  9. Android(安卓)UI开发第八篇——ViewFlipper 左右滑动效果

随机推荐

  1. 通过PHP隐藏SQL中的索引值
  2. 纯JS幻灯片菜单,能够“点击菜单外点击”
  3. 为什么我的DIV小于其内容?
  4. 高分求:如何解析IdHTTP获得的http代码?用ms
  5. 用无序列表键入文本脚本
  6. 如何通过z-index覆盖一个div
  7. 主滑块调整大小到行容器
  8. Windows8/Silverlight/WPF/WP7/HTML5周学
  9. 通过属性名称获取HTML元素
  10. 2.html5的基本格式