【问题标题】:Translate Animation in Android - Starts in centre of Screen在 Android 中翻译动画 - 从屏幕中心开始
【发布时间】:2018-01-01 16:38:07
【问题描述】:

我在RelativeLayout 中有一个Imageview。它应该从屏幕中心(父级)开始,然后到达特定点。实际我使用 xml。 有什么解决办法吗?

我的动画 XML-

<set xmlns:android="http://schemas.android.com/apk/res/android">
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="false">

  <translate
        android:fromYDelta="0%p"
        android:fromXDelta="0%p"
        android:toYDelta="0%"
        android:toXDelta="0%"
        android:duration="1000"
        android:pivotX="0%p"
        android:pivotY="0%p"/>

  <scale xmlns:android="http://schemas.android.com/apk/res/android"
      android:fromXScale="432px"
      android:toXScale="100%"
      android:fromYScale="450px"
      android:toYScale="100%"
      android:duration="1000"
      android:pivotX="0%p"
      android:pivotY="0%p" />
</set>

我已经在fromYDelta 和fromXDelta 和100%p, 50%p, 0%p, 100, 50, 0, 100%, 50% and 0% 中尝试过。没有任何作用! 现在我很困惑! 感谢您的时间和帮助

编辑:

A picture to explain what the Animation should do

【问题讨论】:

  • 它是横幅中的一个元素,它是顶部(32dp marginTop)和中心。但图片需要留在横幅中
  • 是的,我试过了,但我需要想办法把它放回横幅中

标签: android xml animation position translate


【解决方案1】:

在 anim 文件夹中添加这个:

<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXDelta="50%p" android:fromYDelta="50%p" 
    android:toXDelta="50%p" android:toYDelta="0%p" 
    android:duration="1000" 
    android:fillAfter="true" />

在如下代码中实现:

translateAnim= AnimationUtils.loadAnimation(getApplicationContext(),
            R.anim.translate_anim);
imageView.startAnimation(translateAnim);

这会将图像从中心移动到顶部。

【讨论】:

  • 我可以把这个 android:toXDelta="50%p" android:toYDelta="0%p" 改成 android:toXDelta="100%" android:toYDelta="100%"
  • 这完全取决于您希望如何在屏幕上翻译对象。
  • 试过了,但图像不是从中心开始,它比中心更靠右和更低。看起来它以左上角为中心
  • 你的版面设计可能有问题。
  • 对不起我迟到的答案,但我检查了我的设计 2 次......对我来说一切似乎都很好。您还有其他选择或建议吗?
猜你喜欢
  • 1970-01-01
  • 2013-02-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-22
  • 1970-01-01
  • 2013-10-16
  • 1970-01-01
相关资源
最近更新 更多