Android animate TextView from middle of page to the top

元气小坏坏 提交于 2019-12-24 03:37:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!