package com.imooc.viewanim;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.view.animation.AlphaAnimation;import android.view.animation.Animation;import android.view.animation.AnimationSet;import android.view.animation.RotateAnimation;import android.view.animation.ScaleAnimation;import android.view.animation.TranslateAnimation;public class MainActivity extends Activity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);    }    public void btnAlpha(View view) {        //透明度动画 public AlphaAnimation(float fromAlpha, float toAlpha){}        AlphaAnimation aa = new AlphaAnimation(0, 1);        //持续时间        aa.setDuration(1000);        view.startAnimation(aa);    }    public void btnRotate(View view) {//        旋转动画 public RotateAnimation(float fromDegrees, float toDegrees, float pivotX, float pivotY){}//        分别对应起始角度(toDegrees-fromDegrees),旋转中心点。        RotateAnimation ra = new RotateAnimation(90, 240, 50, 50);        ra.setDuration(1000);        view.startAnimation(ra);    }    public void btnRotateSelf(View view) {        //旋转动画,设置旋转参考系        RotateAnimation ra = new RotateAnimation(0, 360,                RotateAnimation.RELATIVE_TO_SELF, 0.5F,                RotateAnimation.RELATIVE_TO_SELF, 0.5F);        ra.setDuration(1000);        view.startAnimation(ra);    }    public void btnTranslate(View view) {        //平移动画        //自身中点做坐标原点(0,0) 向右移动200,向下移动300        TranslateAnimation ta = new TranslateAnimation(0, 200, 0, 300);        ta.setDuration(1000);        view.startAnimation(ta);    }    public void btnScale(View view) {        //缩放动画 public ScaleAnimation(float fromX, float toX, float fromY, float toY){}//        向右放大2,向下放大2 ,后恢复        ScaleAnimation sa = new ScaleAnimation(0, 2, 0, 2);        sa.setDuration(1000);        view.startAnimation(sa);    }    public void btnScaleSelf(View view) {        //缩放动画,设置缩放中心点。        ScaleAnimation sa = new ScaleAnimation(0, 1, 0, 1,                Animation.RELATIVE_TO_SELF, 0.5F,                Animation.RELATIVE_TO_SELF, 0.5F);        sa.setDuration(1000);        view.startAnimation(sa);    }    //动画集合    public void btnSet(View view) {        AnimationSet as = new AnimationSet(true);        as.setDuration(1000);        AlphaAnimation aa = new AlphaAnimation(0, 1);        aa.setDuration(1000);        as.addAnimation(aa);        TranslateAnimation ta = new TranslateAnimation(0, 100, 0, 200);        ta.setDuration(1000);        as.addAnimation(ta);        view.startAnimation(as);    }}
<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" android:paddingLeft="@dimen/activity_horizontal_margin"    android:orientation="vertical"    android:gravity="center_horizontal"    tools:context=".MainActivity">    <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="Alpha"        android:layout_margin="10dp"        android:onClick="btnAlpha" />    <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="Rotate"        android:layout_margin="10dp"        android:onClick="btnRotate" />    <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="Rotate_self"        android:layout_margin="10dp"        android:onClick="btnRotateSelf" />    <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="Translate"        android:layout_margin="10dp"        android:onClick="btnTranslate" />    <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="Scale"        android:layout_margin="10dp"        android:onClick="btnScale" />    <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="Scale_Self"        android:layout_margin="10dp"        android:onClick="btnScaleSelf" />    <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="Anim Set"        android:layout_margin="10dp"        android:onClick="btnSet" />LinearLayout>

更多相关文章

  1. 侧滑菜单(三)
  2. Android在SurfaceView做动画一般方法
  3. 缩放图片 : matrix.setScale(0.5f,0.5f);
  4. ViewFlipper实现View轮播点击等效果
  5. 自定义PopupWindow动画效果
  6. 关键字弹出动画
  7. Property Anim详解
  8. 竖直的完美seekbar,无缝拖动!
  9. Android的图片缩放、拖动

随机推荐

  1. Android中如何修改编译的资源ID值(默认值
  2. Android与设计模式浅谈
  3. 最新!!Android 状态栏详细开发,5分钟精通状
  4. Android Opengl开发一
  5. 打造android万能上拉下拉刷新框架——XRe
  6. Android测试方法总结汇总
  7. Android项目源码混淆问题解决方法
  8. android 优秀开源项目收集
  9. Android设置 Wedgit透明度
  10. [教程] [经验技巧] 任意手机移植ROM 教程