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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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.