Slide down to show textview animation

2019-06-21 03:36发布

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条回答
叛逆
2楼-- · 2019-06-21 04:06

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.

查看更多
登录 后发表回答