Reputation: 1
I have an app with certain background and i want to change it to different background very nicely and gradually on a button click.
I tried doing it with objectanimator by setting background attribute of root layout to two png files that are in my drawable folder but it did not work as type of value of background is in drawable.
My root layout is relative layout and i want to change its background.
RelativeLayout.setbackground(drawable image);
,and objectanimator does not take property with values that are not int,float etc which in my case i have drawable type.
objectanimator.offloat(view,property,values....);
What are the best ways to accomplish this without any library?
Upvotes: 0
Views: 154
Reputation: 2258
Add these two animations to your anim folder
fade_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:fillAfter="true"
android:duration="2000"
/>
</set>
fade_out.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:fillAfter="true"
android:duration="2000"
/>
</set>
and then in your Activity/Fragment
Animation fadeIn = AnimationUtils.loadAnimation(YourActivity.this, R.anim.fade_in);
imageView.startAnimation(fadeIn);
fadeIn.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
Animation fadeOut = AnimationUtils.loadAnimation(YourActivity.this, R.anim.fade_out);
imageView.startAnimation(fadeOut);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
Upvotes: 0