【问题标题】:Android Translate AnimationAndroid 翻译动画
【发布时间】:2012-04-13 06:00:56
【问题描述】:

我有一个 ImageView,它在底部上方 250dp 并且带有翻译动画,我想将其移动到底部上方 50dp。

我知道如何使用翻译动画,但我不知道 ToYValue 字段是什么。

代码将是这样的:

TranslateAnimation translate = new TranslateAnimation(Animation.RELATIVE_TO_PARENT,0,Animation.RELATIVE_TO_PARENT,0,Animation.ABSOLUTE,250,Animation.ABSOLUTE,50);
translate.setDuration(1000);
translate.reset();  
translate.setFillAfter(true);
iv.clearAnimation();
iv.startAnimation(translate);

【问题讨论】:

    标签: android imageview translate-animation


    【解决方案1】:

    您希望 fromYValue 为 0,表示从当前位置开始,toYValue 为 50,表示向下移动 50 个像素。请注意,这些值以像素为单位,而不是 dp。如果它必须在 dp 中,那就是另一个问题了..

    关键在于 TranslateAnimation 文档“改变 Y 坐标以在动画开始时应用”中的“更改”一词。

    http://developer.android.com/reference/android/view/animation/TranslateAnimation.html

    【讨论】:

      猜你喜欢
      • 2011-09-18
      • 1970-01-01
      • 2013-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-23
      • 1970-01-01
      • 2015-04-19
      相关资源
      最近更新 更多