【发布时间】:2016-12-10 18:26:57
【问题描述】:
我对动画中的 %p 单位感到困惑。 这是我的动画文件 test.xml
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:duration="1000"
android:fillAfter="true"
android:fromXDelta="0"
android:toXDelta="0"
android:fromYDelta="50%p"
android:toYDelta="50%p" />
我将这个动画用于我的视图
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:layout_alignParentTop="true"
android:background="#ff2"
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="@+id/view" />
</RelativeLayout>
但是,如果我将视图的位置更改为它的父视图的中心,并且动画后视图的位置不正确
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:layout_centerVertical="true"
android:background="#ff2"
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="@+id/view" />
</RelativeLayout>
我认为对于同一个父母,50%p 总是一样的,但结果却不是。为什么?
【问题讨论】:
-
是 50%p 的平均值:currentY + 50% * parentHeight?
标签: android animation translate-animation