Android从页面中间到顶部为TextView设置动画 [英] Android animate TextView from middle of page to the top

查看:297
本文介绍了Android从页面中间到顶部为TextView设置动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在XML文件的页面中间有一个TextView。当我单击它时,我想以动画方式将其移动到容器的顶部。

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?

谢谢。

推荐答案

定义翻译动画并将其放在res / anim中

Define a translate animation and put it in your res/anim folder.

此文件夹将视图向上移动175 dp,并根据需要调整android:toYDelta。

This one moves the view up by 175 dp, adjust android:toYDelta accordingly for your purposes.

my_anim.xml:

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>

从代码中加载:

Animation myAnim = AnimationUtils.loadAnimation(getActivity(), R.anim.my_anim);

然后在要对其设置动画时在TextView上设置它:

Then set it on your TextView when you want it to animate:

myTextView.startAnimation(myAnim);

这篇关于Android从页面中间到顶部为TextView设置动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆