android - 如何将动画缩放到特定大小

标签 android scaleanimation

我有一个具有起始大小(Width1 和 Height1)的 View 。我想创建一个动画以将其大小更改为最终大小(Width2 和 Height2)。我一直在阅读有关 ScaleAnimation 的内容,但我无法理解比例因子。

你能告诉我构造函数的值 a、b、c 和 d 吗:

ScaleAnimation scaleAnimation = new ScaleAnimation(a, b, c, d);

谢谢

最佳答案

4-floats ScaleAnimation 构造函数的参数如下:

fromX   Horizontal scaling factor to apply at the start of the animation
toX     Horizontal scaling factor to apply at the end of the animation
fromY   Vertical scaling factor to apply at the start of the animation
toY     Vertical scaling factor to apply at the end of the animation 

所有值都是 float ——它们不是以像素为单位表示大小,而是相对比例因子。 因此,要从 width1 缩放到 width2 以及从 height1 缩放到 height2 您需要设置:

ScaleAnimation scaleAnimation = 
   new ScaleAnimation(1f, 1f * width2 / width1, 1f, 1f * height2 / height1);

关于android - 如何将动画缩放到特定大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22895195/

相关文章:

android - 找不到类 'org.codehaus.jackson.map.ObjectMapper'?

android - 操作栏不显示

android - 在 ImageView 上的 android 中缩放动画不流畅

Android - ObjectAnimator 设置枢轴值

Android AppStateManager::检测到 DataBuffer 对象内的内部数据泄漏

java - ListView 与 CheckBox 滚动问题

android - 添加了 API 的 Android 4.1.2 可以与低功耗​​蓝牙通信吗?

java - Android 缩放动画使用不正确的坐标

android - ScaleAnimation 从大到小