android动画页面,Android动画(Animations)

动画类型

Android的animation由四种类型组成

XML中

alpha

渐变透明度动画效果

scale

渐变尺寸伸缩动画效果

translate

画面转换位置移动动画效果

rotate

画面转移旋转动画效果

Java代码中

AlphaAnimation

渐变透明度动画效果

ScaleAnimation

渐变尺寸伸缩动画效果

TranslateAnimation

画面转换位置移动动画效果

RotateAnimation

画面转移旋转动画效果

1、main.xml

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical" >

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:orientation="horizontal" >

android:id="@+id/rotateButton"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="旋转" />

android:id="@+id/scaleButton"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="缩放" />

android:id="@+id/alphaButton"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="淡入淡出" />

android:id="@+id/translateButton"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="移动" />

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical" >

android:id="@+id/image"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerInParent="true"

android:src="@drawable/an" />

2、.java文件

importandroid.app.Activity;

importandroid.os.Bundle;

importandroid.view.View;

importandroid.view.View.OnClickListener;

import android.view.animation.AlphaAnimation;

import android.view.animation.Animation;

importandroid.view.animation.AnimationSet;

importandroid.view.animation.RotateAnimation;

importandroid.view.animation.ScaleAnimation;

import android.view.animation.TranslateAnimation;

importandroid.widget.Button;

importandroid.widget.ImageView;

public class Animation1Activity extends Activity{

private Button rotateButton = null;

private Button scaleButton = null;

private Button alphaButton = null;

private Button translateButton = null;

private ImageView mImageView = null;

private Animation Alpha;

private Animation Scale;

private Animation Translate;

private AnimationRotate;

@Override

public void onCreate(BundlesavedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

rotateButton =(Button)findViewById(R.id.rotateButton);

scaleButton =(Button)findViewById(R.id.scaleButton);

alphaButton =(Button)findViewById(R.id.alphaButton);

translateButton =(Button)findViewById(R.id.translateButton);

mImageView = (ImageView)findViewById(R.id.image);

rotateButton.setOnClickListener(newRotateButtonListener());

scaleButton.setOnClickListener(newScaleButtonListener());

alphaButton.setOnClickListener(newAlphaButtonListener());

translateButton.setOnClickListener(

new TranslateButtonListener());

}

class AlphaButtonListener implementsOnClickListener{

public void onClick(Viewv) {

Alpha= animationUtils.loadAnimation(this,R.anim.alpha_action);

mImageView.startAnimation(Alpha);

}

}

class RotateButtonListener implementsOnClickListener{

public void onClick(Viewv) {

Rotate = AnimationUtils.loadAnimation(this,R.anim.rotate_action);

mImageView.startAnimation(Rotate);

}

class ScaleButtonListener implementsOnClickListener{

public void onClick(Viewv) {

Scale =AnimationUtils.loadAnimation(this,R.anim.scale_action);

mImageView.startAnimation(Scale);

}

class TranslateButtonListener implementsOnClickListener{

public void onClick(Viewv) {

Translate =AnimationUtils.loadAnimation(this,R.anim.translate_action);

mImageView.startAnimation(Translate);

}

}

}

1: alpha_action.xml

android:fromAlpha="0.1"

android:toAlpha="1.0"

android:duration="3000"

/>

2:rotate_action.xml

android:interpolator="@android:anim/accelerate_decelerate_interpolator"

android:fromDegrees="0"

android:toDegrees="+350"

android:pivotX="50%"

android:pivotY="50%"

android:duration="3000"/>

3: scale_action.xml

android:interpolator="@android:anim/accelerate_decelerate_interpolator"

android:fromXScale="0.0"

android:toXScale="1.4"

android:fromYScale="0.0"

android:toYScale="1.4"

android:pivotX="50%"

android:pivotY="50%"

android:fillAfter="false"

android:duration="700"/>

4: translate_action.xml

android:fromXDelta="30"

android:toXDelta="-80"

android:fromYDelta="30"

android:toYDelta="300"

android:duration="2000"/>

下载地址

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值