I am interested in adding an animation on toggling the visibility of a TextView in my android application. I would like it to not just set the Visibility to Visibility.GONE and Visibility.VISIBLE - instead I want it to have a jquery like slide effect. Is this easy to accomplish?
To start the animation we need to call the startAnimation() function on the UI element as shown in the snippet below: sampleTextView. startAnimation(animation); Here we perform the animation on a textview component by passing the type of Animation as the parameter.
A property animation changes a property's (a field in an object) value over a specified length of time. To animate something, you specify the object property that you want to animate, such as an object's position on the screen, how long you want to animate it for, and what values you want to animate between.
The animations are basically of three types as follows: Property Animation. View Animation. Drawable Animation.
Shouldn't be hard, just write up the animation in xml and place it under res/anim. I'm not familiar with the exact animation you're after, but a slide in looks something like this:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:repeatCount="0" >
<translate
android:duration="@android:integer/config_mediumAnimTime"
android:fromYDelta="-100%"
android:toYDelta="0%" />
<alpha
android:duration="@android:integer/config_mediumAnimTime"
android:fromAlpha="0.0"
android:toAlpha="1.0" />
</set>
You set it on the view like this:
Animation anim = AnimationUtils.loadAnimation(this, R.anim.slide_in_top);
view.startAnimation(anim);
If you ensure you set the 'fillAfter' attribute in the xml, you won't need to worry about setting visibility (as long as your animation changes the alpha of course).
To slide out just make another animation that does the opposite.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With