20 Animation

4中特效对应四个类。


package mars.animations01;

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 MainActivity extends Activity {
/** Called when the activity is first created. */
private ImageView imageView = null;
private Button rotateButton = null;
private Button scaleButton = null;
private Button alphaButton = null;
private Button translateButton = null;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imageView = (ImageView) findViewById(R.id.imageViewId);

rotateButton = (Button) findViewById(R.id.rotateButtonId);
rotateButton.setOnClickListener(new RotateButtonListener());

scaleButton = (Button) findViewById(R.id.scaleButtonId);
scaleButton.setOnClickListener(new ScaleButtonListener());

alphaButton = (Button) findViewById(R.id.alphaButtonId);
alphaButton.setOnClickListener(new AlphaButtonListener());

translateButton = (Button) findViewById(R.id.translateButtonId);
translateButton.setOnClickListener(new TranslateButtonListener());
}

private class RotateButtonListener implements OnClickListener {

@Override
public void onClick(View view) {
AnimationSet animationSet = new AnimationSet(true);
RotateAnimation rotateAnimation = new RotateAnimation(0, 360,
Animation.RELATIVE_TO_PARENT, 1f,
Animation.RELATIVE_TO_PARENT, 0f);
rotateAnimation.setDuration(5000);
animationSet.addAnimation(rotateAnimation);
imageView.startAnimation(animationSet);
}
}

private class ScaleButtonListener implements OnClickListener {

@Override
public void onClick(View view) {
AnimationSet animationSet = new AnimationSet(true);
ScaleAnimation scaleAnimation = new ScaleAnimation(1, 0.1f, 1, 0.1f,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
animationSet.addAnimation(scaleAnimation);
animationSet.setStartOffset(1000);
animationSet.setFillAfter(true);
animationSet.setFillBefore(false);
animationSet.setDuration(2000);
imageView.startAnimation(animationSet);
}

}

private class AlphaButtonListener implements OnClickListener {

@Override
public void onClick(View view) {
//创建一个AnimationSet对象
AnimationSet animationSet = new AnimationSet(true);
//创建一个AlphaAnimation对象
AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0);
//设置动画执行的时间(单位:毫秒)
alphaAnimation.setDuration(1000);
//将AlphaAnimation对象添加到AnimationSet当中
animationSet.addAnimation(alphaAnimation);
//使用ImageView的startAnimation方法开始执行动画
imageView.startAnimation(animationSet);
}

}

private class TranslateButtonListener implements OnClickListener {

@Override
public void onClick(View view) {
AnimationSet animationSet = new AnimationSet(true);
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);
animationSet.addAnimation(translateAnimation);
imageView.startAnimation(animationSet);
}
}
}

20 Animation,布布扣,bubuko.com

时间: 2024-08-07 08:40:01

20 Animation的相关文章

iOS开发——动画编程Swift篇&(五)CAKeyframeAnimation

CAKeyframeAnimation 1 //CAKeyframeAnimation-关键针动画 2 @IBAction func cakFly() 3 { 4 let animation = CAKeyframeAnimation(keyPath: "position") 5 6 //设置5个位置点 7 let p1 = CGPointMake(0.0, 0.0) 8 let p2 = CGPointMake(320, 0.0) 9 let p3 = CGPointMake(0,

loading页面

虽然今天考试,但还是要写我的每日一博^_^ loading页面的效果图 看起来简单,实际上要写的东西不少T_T 1 <!DOCTYPE html> 2 <html lang="en"> 3 4 <head> 5 <meta charset="UTF-8"> 6 <title>Document</title> 7 <style> 8 body { 9 background: gains

增加动画的效果

a) alpha(AlphaAnimation) 渐变透明 b) scale(ScaleAnimation) 渐变尺寸伸缩 c) translate(TranslateAnimation) 画面转换.位置移动 d) rotate(RotateAnimation) 画面转移,旋转动画 1 public void onClick(View v) { 2 if(grid_list) { 3 lv.setVisibility(View.VISIBLE); 4 gv.setVisibility(View.

iOS-CALayer &amp;&amp; CAAnimation

一.CALayer 1.CALayer CALayer属于QuartzCore.framework框架,从Xcode5起我们不必要手动导入这个库. CALayer我们可以简单理解为一个层.当我们绘制的UIView能在屏幕显示,其实质是因为这个层. 我们下面通过代码理解一下CALayer的基本用法. CALayer *caLayer = [CALayer layer]; caLayer.backgroundColor = [UIColor cyanColor].CGColor; caLayer.f

iOS开发——动画编程Swift篇&amp;(四)CABasicAnimation动画

CABasicAnimation动画 1 //CABasicAnimation-不透明度 2 @IBAction func cabOpacity() 3 { 4 let animation = CABasicAnimation(keyPath: "opacity") 5 6 animation!.fromValue = 1.0 7 animation!.toValue = 0.0 8 animation.duration = 3.0 9 self.testImageView.layer

Android学习笔记:摇一摇功能的实现

首先需要用到一个摇一摇的工具类 ShakeManager.java 1 package com.wuxianedu.oschina.utils; 2 3 import android.content.Context; 4 import android.hardware.Sensor; 5 import android.hardware.SensorEvent; 6 import android.hardware.SensorEventListener; 7 import android.hard

iOS_SN_push/pop转场动画封装和一般动画封装

封装类中的方法: 1 #import <Foundation/Foundation.h> 2 3 #import <UIKit/UIKit.h> 4 5 6 7 8 9 @interface AnimationEffect : NSObject 10 11 12 13 14 15 /** 16 17 * push/pop转场动画封装 18 19 * 20 21 * @param type 动画类型 22 23 * @param subType 动画子类型 24 25 * @para

纯CSS3打造非常炫的加载动画

纯css3打造的一款非常炫的加载图.用在需要一定时间加载的地方非常合适.先上效果图: 点击这里在线预览 代码非常简单.没有用任何javascript代码.纯css3实现. html代码: <div class="content"> <div style="width: 970px; margin: auto"> </div> <div class="rotate"> <span class=&

天猫首页迷思之-jquery实现左侧广告牌图片轮播

本次要实现的是天猫首页每个楼层左侧的图片轮播效果.见图: 功能点有:点击右箭头向右滑动:点击左箭头向左滑动:什么都不点自动滑动. 1.实现样式.简单分析一下大概的html结构.一个大的div里面包含两个箭头以及轮播的容器.图片是由三个p标签组成,每个p标签中包含3个图片.css见github 1 <div class="floor-show-middle"> 2 <a class="floor-show-middle-arrow arrow-left&quo