An Alpha Animation is animation that controls the alpha level of an object, i.e. fading it in and out. In Android, you can apply that fading effect to almost anything, from simple text, to images, buttons, check boxes, etc…
This can be done both from xml and from java class.
Here I will explain a simple way to give a FadeIn and FadeOut for a textview on button click..
This can be done both from xml and from java class.
Here I will explain a simple way to give a FadeIn and FadeOut for a textview on button click..
public class Textviewanimation extends Activity { Animation fadeIn,fadeOut; TextView tv; Button startanimation; Boolean fadeflag=true; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_textviewanimation); tv=(TextView) findViewById(R.id.textview); startanimation=(Button) findViewById(R.id.button1); fadeIn = new AlphaAnimation(0.0f , 1.0f ) ; fadeIn.setDuration(1200); fadeIn.setFillAfter(true); fadeOut = new AlphaAnimation(1.0f , 0.0f); fadeOut.setDuration(1200); fadeOut.setFillAfter(true); startanimation.setText("Start fadeIn"); startanimation.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { if(fadeflag) { startanimation.setText("Start fadeOut"); tv.setText("This is an animated textview"); tv.startAnimation(fadeIn); fadeflag=false; } else { startanimation.setText("Start fadeIn"); tv.setText("This is an animated textview"); tv.startAnimation(fadeOut); fadeflag=true; } } }); } }
and res/anim/fadeout
Then in java
Animation animationFadeIn = AnimationUtils.loadAnimation(this,R.anim.fadein); tv.startAnimation(animationFadeIn);same way call the other
see more
Falling animation ..
Comments
Post a Comment