Pol Hallen
Pol Hallen

Reputation: 1862

textswitcher change default fade

I using this code to create a textswitcher, I'd like set by values a different time of fade. How I create other xml to set several fade?

mSwitcher = (TextSwitcher) findViewById(R.id.switcher);
mSwitcher.setFactory(this);
Animation in = AnimationUtils.loadAnimation(this,android.R.anim.fade_in);
Animation out = AnimationUtils.loadAnimation(this,android.R.anim.fade_out);
mSwitcher.setInAnimation(in);
mSwitcher.setOutAnimation(out);

Upvotes: 1

Views: 703

Answers (1)

FoamyGuy
FoamyGuy

Reputation: 46856

make a folder called anim inside of your project res folder. Add some XML files to it like this:

fadin.xml

<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
       android:interpolator="@android:anim/accelerate_interpolator"
       android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="300" />

fadout.xml

<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
       android:interpolator="@android:anim/accelerate_interpolator"
       android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="300" />

Change these lines in your java:

Animation in = AnimationUtils.loadAnimation(this,android.R.anim.fade_in);
Animation out = AnimationUtils.loadAnimation(this,android.R.anim.fade_out);

to be like this:

Animation in = AnimationUtils.loadAnimation(this,R.anim.fadein);
Animation out = AnimationUtils.loadAnimation(this,R.anim.fadeout);

Tweak the values in the xml file to make the fade appear as you want.

Upvotes: 2

Related Questions