Animation动画之alpha

来源:互联网 发布:网络流媒体地址 编辑:程序博客网 时间:2024/05/21 11:28


一、Android的Anotation由四种类型构成:alpha,scale,translate,rotate;

二、在xml配置文件中

alpha: 渐变透明度动画效果;

scale: 渐变尺寸缩放动画效果

translate: 画面位置移动动画效果

rotate: 画面旋转 动画效果

 

三、xml配置文件存放位置

a)        存放在res/anim文件加下,类访问方式是R.anim.XXX.xml,

如图:


代码如下:

<?xml version="1.0" encoding="utf-8"?><alpha xmlns:android="http://schemas.android.com/apk/res/android"    android:duration="3000"    android:fillBefore="true"    android:fromAlpha="1.0"    android:toAlpha="0.1" ></alpha><!-- fillBefore是指动画结束时画面停留在第一帧,fillAfter是指动画结束是画面停留在最后一帧 -->


四、activity中主要代码:

package com.example.animation;import android.app.Activity;import android.app.ActionBar;import android.app.Fragment;import android.os.Bundle;import android.util.Log;import android.view.LayoutInflater;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.view.View.OnClickListener;import android.view.ViewGroup;import android.view.animation.Animation;import android.view.animation.Animation.AnimationListener;import android.view.animation.AnimationUtils;import android.widget.Button;import android.widget.TextView;import android.widget.Toast;import android.os.Build;public class MainActivity extends Activity implements AnimationListener{private final String TAG = "animation" ;Button alpha_btn;TextView tv ;Animation alphaAnimation;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);//加载animation动画的xml文件alphaAnimation = AnimationUtils.loadAnimation(this, R.anim.alphaanim);tv = (TextView) findViewById(R.id.alpha_textId) ;alpha_btn = (Button) findViewById(R.id.alpha_btnId);alpha_btn.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {//为控件textView添加动画效果tv.startAnimation(alphaAnimation);}});//为动画设置监听alphaAnimation.setAnimationListener(this);}@Overridepublic void onAnimationStart(Animation animation) {//动画开始进入onAnimationStart方法Log.d(TAG, "onAnimationStart") ;}@Overridepublic void onAnimationEnd(Animation animation) {//动画结束,进入onAnimationEnd方法Log.d(TAG, "onAnimationEnd") ;}@Overridepublic void onAnimationRepeat(Animation animation) {Log.d(TAG, "onAnimationRepeat") ;}}



参考博客:http://blog.csdn.net/harvic880925/article/details/39996643






0 0