问题
I have a TextView in the middle of my page in an XML file. I'd like to move this in an animate way to the top of it's container when I click on it.
What's the best way to do this?
Thanks.
回答1:
Define a translate animation and put it in your res/anim folder.
This one moves the view up by 175 dp, adjust android:toYDelta accordingly for your purposes.
my_anim.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/linear_interpolator">
<translate android:fromYDelta="0" android:toYDelta="-175" android:duration="700"/>
</set>
Load it from code:
Animation myAnim = AnimationUtils.loadAnimation(getActivity(), R.anim.my_anim);
Then set it on your TextView when you want it to animate:
myTextView.startAnimation(myAnim);
来源:https://stackoverflow.com/questions/26807423/android-animate-textview-from-middle-of-page-to-the-top