android 个动画中的 %p
%p in android animation
我对动画中的 %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>
动画之后,视图几乎位于屏幕中央,正如我所料。
但是,如果我将视图的位置更改为居中,则它是 parent,并且动画后视图的位置不正确
<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>
结果如下:
我认为对于相同的parent,50%p 总是相同的,但结果却不同。为什么?
你可以试试
android:fromYDelta="0%p"
android:toYDelta="50%p"
然后您将在 1000 毫秒内看到您的动画
所以
android:fromYDelta=
表示开始位置基于viewself
android:toYDelta=
表示基于viewself的结束位置
当您设置视图时 android:layout_alignParentTop="true"
,View 动画从上到中。
当您设置视图时 android:layout_alignParentCenter="true"
,View 动画从中心到底部。
我对动画中的 %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>
动画之后,视图几乎位于屏幕中央,正如我所料。
但是,如果我将视图的位置更改为居中,则它是 parent,并且动画后视图的位置不正确
<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>
结果如下:
我认为对于相同的parent,50%p 总是相同的,但结果却不同。为什么?
你可以试试
android:fromYDelta="0%p"
android:toYDelta="50%p"
然后您将在 1000 毫秒内看到您的动画
所以
android:fromYDelta=
表示开始位置基于viewselfandroid:toYDelta=
表示基于viewself的结束位置
当您设置视图时 android:layout_alignParentTop="true"
,View 动画从上到中。
当您设置视图时 android:layout_alignParentCenter="true"
,View 动画从中心到底部。