从特定位置从上到下开始简单的动画 [英] Start simple Animation top to bottom from a specific position

查看:97
本文介绍了从特定位置从上到下开始简单的动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要制作一个从上到下执行动画的文本视图,并且动画以y值50开始.该怎么做?预先感谢.

I need to make a textview that perform an animation from top to bottom and the animation start with the y value 50. How to do it? Thanks in advance.

推荐答案

您可以使用TranslateAnimation. TranslateAnimation使用增量,因此要计算从屏幕顶部开始50px的位置,减去视图顶部和顶部加50. 在此示例中,我通过向fromY添加一些值来设置toY. 这是代码:

You can use TranslateAnimation. TranslateAnimation uses deltas, so to calculate the position of 50px from the top of the screen, subtract the top of the view & add 50. In this example, I set the toY by adding some value to the fromY. Here's the code:

int fromY = 50 - view.getTop();
int toY = fromY + someValue;
TranslateAnimation animation = new TranslateAnimation(0, 0, fromY, toY);
animation.setDuration(someDuration);
view.startAnimation(animation);

希望这会有所帮助:)

这篇关于从特定位置从上到下开始简单的动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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