简体   繁体   English

Android动画-将视图动画化到特定位置

[英]Android Animations - Animate view to a specific position

I have a load screen/pop up screen which is a fragment which shows up whenever I call an API. 我有一个加载屏幕/弹出屏幕,它是片段,每当我调用API时都会显示。 I like how it looks currently, but I would like to liven it up by adding a bunch of animations to the views in the load screen. 我喜欢它的当前外观,但是我想通过在加载屏幕的视图中添加一堆动画来使其生动。

I am using the property animation framework to good effect for scaling and changing the alpha value(transparency) of views in their current positions. 我正在使用属性动画框架来很好地缩放和更改视图在其当前位置的alpha值(透明度)。

I am now trying to get a view to animate(translate + alpha change) to it's current position in the static screen. 我现在试图获取一个视图以使其在静态屏幕中的当前位置动画化(翻译+ Alpha更改)。 I do not however, wish to hardcode values since this would clearly mess up the alignment of views and cause overlaps and other problems. 但是,我不希望对值进行硬编码,因为这显然会弄乱视图的对齐并导致重叠和其他问题。

How do I translate a view from some point outside the screen, to it's current position in the static screen? 如何将视图从屏幕外的某个点转换为静态屏幕中的当前位置? Eg: In my static screen if I have a view that is centre aligned in the parent layout, how do I animate the view from a position outside the screen to this current position. 例如:在我的静态屏幕上,如果我的视图在父级布局中居中对齐,那么如何将视图从屏幕外的位置动画化为当前位置。 I have tried the following but it does not work since it expects float values. 我尝试了以下方法,但是由于期望浮点值,因此无法正常工作。

    <set android:ordering="together">
    <objectAnimator
        android:duration="1500"
        android:propertyName="y"
        android:valueFrom="0"
        android:valueTo="50%p"
        android:valueType="floatType" />
    <objectAnimator
        android:duration="1500"
        android:propertyName="alpha"
        android:valueFrom="0"
        android:valueTo="1"
        android:valueType="floatType" />
</set>

I am trying to keep as much of the animation logic in xmls as possible. 我正在尝试将尽可能多的动画逻辑保留在xml中。

经过更多研究之后,我遇到了translationY(和translation X)属性,这似乎是我所寻找的属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM