你好,游客 登录 注册 搜索
背景:
阅读新闻

Android Action Bar 自定义View

[日期:2013-06-04] 来源:Linux社区  作者:lichen [字体:大 中 小]

AnimationDemoActivity.java

package com.tianjf;

import Android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
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;
import android.widget.Button;
import android.widget.ImageView;

public class AnimationDemoActivity extends Activity implements OnClickListener {

 private ImageView mImageView;
 private Button mAlphaButton;
 private Button mScaleButton;
 private Button mRotateButton;
 private Button mTranslateButton;

 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  mImageView = (ImageView) findViewById(R.id.imageView);
  mAlphaButton = (Button) findViewById(R.id.alphaButton);
  mScaleButton = (Button) findViewById(R.id.scaleButton);
  mRotateButton = (Button) findViewById(R.id.rotateButton);
  mTranslateButton = (Button) findViewById(R.id.translateButton);

  mAlphaButton.setOnClickListener(this);
  mScaleButton.setOnClickListener(this);
  mRotateButton.setOnClickListener(this);
  mTranslateButton.setOnClickListener(this);
 }

 @Override
 public void onClick(View v) {
  switch (v.getId()) {
  case R.id.alphaButton:
   // 创建一个AnimationSet对象(AnimationSet是存放多个Animations的集合)
   AnimationSet animationSet = new AnimationSet(true);
   // 创建一个AlphaAnimation对象(参数表示从完全不透明到完全透明)
   AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0);
   // 设置动画执行的时间(单位:毫秒)
   alphaAnimation.setDuration(1000);
   // 将AlphaAnimation对象添加到AnimationSet当中
   animationSet.addAnimation(alphaAnimation);
   // 使用ImageView的startAnimation方法开始执行动画
   mImageView.startAnimation(animationSet);
   break;

  case R.id.scaleButton:
   // 创建一个AnimationSet对象(AnimationSet是存放多个Animations的集合)
   animationSet = new AnimationSet(true);
   // 创建一个ScaleAnimation对象(以某个点为中心缩放)
   ScaleAnimation scaleAnimation = new ScaleAnimation(1, 0.1f, 1, 0.1f,
     Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
   // 设置动画执行之前等待的时间(单位:毫秒)
   scaleAnimation.setStartOffset(1000);
   // 设置动画执行的时间(单位:毫秒)
   scaleAnimation.setDuration(2000);
   // 如果fillAfter设为true,则动画执行后,控件将停留在动画结束的状态
   // 运行了一下发现以下奇怪的现象
   // scaleAnimation.setFillAfter(true);不会停留在动画结束的状态
   // animationSet.setFillAfter(true);则会停留在动画结束的状态
   animationSet.setFillAfter(true);
                        // 将ScaleAnimation对象添加到AnimationSet当中
                       animationSet.addAnimation(scaleAnimation);
                        // 使用ImageView的startAnimation方法开始执行动画
                       mImageView.startAnimation(animationSet);
   break;

  case R.id.rotateButton:
   // 创建一个AnimationSet对象(AnimationSet是存放多个Animations的集合)
   animationSet = new AnimationSet(true);
   // 创建一个RotateAnimation对象(以某个点为圆心旋转360度)
   RotateAnimation rotateAnimation = new RotateAnimation(0, 360,
     Animation.RELATIVE_TO_PARENT, 0.5f, Animation.RELATIVE_TO_PARENT, 0.25f);
   // 设置动画执行的时间(单位:毫秒)
   rotateAnimation.setDuration(5000);
   // 将RotateAnimation对象添加到AnimationSet当中
   animationSet.addAnimation(rotateAnimation);
   // 使用ImageView的startAnimation方法开始执行动画
   mImageView.startAnimation(animationSet);
   break;

  case R.id.translateButton:
   // 创建一个AnimationSet对象(AnimationSet是存放多个Animations的集合)
   animationSet = new AnimationSet(true);
   // 创建一个RotateAnimation对象(从某个点移动到另一个点)
   TranslateAnimation translateAnimation = new TranslateAnimation(
     Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0.5f,
     Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 1.0f);
   // 设置动画执行的时间(单位:毫秒)
   translateAnimation.setDuration(1000);
   // 将TranslateAnimation对象添加到AnimationSet当中
   animationSet.addAnimation(translateAnimation);
   // 使用ImageView的startAnimation方法开始执行动画
   mImageView.startAnimation(animationSet);
   break;

  default:
   break;
  }
 }
}

 

linux
相关资讯       Android action  Android自定义View 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • ���与本评论即表明您已经阅读并接受上述条款