动画的淡入淡出效果

这是系统自带的动画效果,现在网上还有很多的框架,实现各种动画效果,有兴趣的,可以去研究一下

package com.gjp.activity.ztast2; 

import android.app.Activity; 
import android.graphics.drawable.TransitionDrawable; 
import android.os.Bundle; 
import android.view.View; 
import android.view.animation.AlphaAnimation; 
import android.widget.Button; 
import android.widget.ImageView; 

public class AnimationActivity extends Activity implements View.OnClickListener { 

private ImageView iv_alpha; 
private AlphaAnimation alphaAnimation; 
private TransitionDrawable transitionDrawable; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.acivity_animation); 

Button btn_play1 = (Button) findViewById(R.id.btn_play1); 
Button btn_play2 = (Button) findViewById(R.id.btn_play2); 

iv_alpha = (ImageView) findViewById(R.id.iv_alpha); 
iv_alpha.setAlpha(0.0f); 
alphaAnimation = new AlphaAnimation(0.0f, 1.0f); 
alphaAnimation.setDuration(3000); 
alphaAnimation.setFillAfter(true); 

btn_play1.setOnClickListener(this); 
btn_play2.setOnClickListener(this); 
} 


@Override 
public void onClick(View v) { 
if (v.getId() == R.id.btn_play1) { 
iv_alpha.setImageResource(R.mipmap.alpha_begin); 
iv_alpha.setAlpha(1.0f); 
iv_alpha.setAnimation(alphaAnimation); 
alphaAnimation.start(); 
} else if (v.getId() == R.id.btn_play2) { 
iv_alpha.setImageResource(R.mipmap.alpha_begin); 
iv_alpha.setAlpha(0.3f); 
iv_alpha.setAnimation(alphaAnimation); 
alphaAnimation.start(); 
} 

} 
}

你可能感兴趣的:(动画的淡入淡出效果)