Reputation: 27
I am making an application in android for picture slide show. I have tried the following code:
class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Drawable backgrounds[] = new Drawable[2];
Resources res = getResources();
backgrounds[0] = res.getDrawable(android.R.drawable.btn_star_big_on);
backgrounds[1] = res.getDrawable(android.R.drawable.btn_star_big_off);
TransitionDrawable crossfader = new TransitionDrawable(backgrounds);
ImageView image = (ImageView)findViewById(R.id.image);
image.setImageDrawable(crossfader);
crossfader.startTransition(3000);
}
}
This code successfully bring the new image on top but previous image is not faded out. Can anyone help me on it?
Upvotes: 0
Views: 72
Reputation: 3067
You need to enable the cross fade on your transition to have both of your images fade. Use the method setCrossFadeEnabled
to enable it by setting it tu true
.
See documentation here http://developer.android.com/reference/android/graphics/drawable/TransitionDrawable.html#setCrossFadeEnabled(boolean)
Upvotes: 1