I've read this stackoverflow question and answer and tried to implement a text fade in and out:
How to make text fade in and out in Android?
This is my implementation:
public class ShowActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show);
final TextView mSwitcher = (TextView) findViewById(R.id.textFade);
mSwitcher.setText("old text");
final Animation in = new AlphaAnimation(0.0f, 1.0f);
in.setDuration(5000);
final Animation out = new AlphaAnimation(1.0f, 0.0f);
out.setDuration(5000);
out.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationEnd(Animation animation) {
mSwitcher.setText("New Text");
mSwitcher.startAnimation(in);
}
@Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationStart(Animation arg0) {
// TODO Auto-generated method stub
}
});
mSwitcher.startAnimation(out);
mSwitcher.setText("Text 1.");
mSwitcher.startAnimation(in);
mSwitcher.startAnimation(out);
mSwitcher.setText("Text 2.");
mSwitcher.startAnimation(in);
}
}
The problem is, that only text 2 appears and it only fade in and not fade out. What could be wrong?
Look at my class. You only have to include it.
Note that this class can't be used inside ListView items managed by ViewHolders.
The problem is that you are starting a fade in animation immediately every time you start a fade out animation.
I was able to modify your code and get a simple example working, here's the code: