Slide down to show textview animation
Asked Answered
F

1

6

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?

Finalize answered 30/5, 2013 at 23:22 Comment(5)
You can check my answer hereLens
@Yul, This is great! But it only appears to function once per activity load? I can expand the view, then collapse the view just fine. But if I try and do it again it does some funky stuff or simply doesn't do anything.Finalize
Did you put that snippet in your textView_onclick? Example hereLens
I did follow the example, yes. I believe it has to do with my textview being variable height, where this example is an expandable list view always set to a height of 50dp...Finalize
You can calculate textview height on runtime. Example. If it's not work i'll add my snippet :)Lens
Y
14

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.

Ytterbia answered 31/5, 2013 at 0:10 Comment(2)
Actually this isn't what I was looking for. I was hoping for an animation that would slide down and reveal at the same time. In other words, the textview starts completely invisible. Then, the user clicks a button and the textview becomes visible gradually from top to bottom. If the user clicks the button again, it becomes invisible from bottom to top.Finalize
I don't have time to play around with it right now unfortunatly but off the top of my head it sounds like you might need to look at the <scale> tags. I'm assuming you're using an IDE like eclipse so you can just command (or ctrl) + space to see your options. Remove the translate and alpha tags in the xml and see what properties scale has, or if there is another tag that sounds right.Ytterbia

© 2022 - 2024 — McMap. All rights reserved.