2016-08-04 11 views
1

アニメーションで%p単位について混乱しています。 は、ここに私のアニメーションファイルのtest.xml%p in android animation

<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> 

やアニメーションの後、私は予想通り、ビューはほぼ、画面の中心地であるため、このアニメーションを使用します。 enter image description here

しかし、私は、ビューの位置が中央に変更した場合、それは親だし、アニメーションの後にビューの位置が正しくありません。ここで

<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> 

が結果です: enter image description here

私は同じ親のために、50%pはいつも同じだと思いますが、結果はそうではありません。どうして?あなたは

android:fromYDelta="0%p" 
android:toYDelta="50%p" 

を試すことができます

+1

この投稿を参照してください:http://stackoverflow.com/a/4412183/5519005 –

+0

は50%p平均です:currentY + 50%* parentHeight? – maphongba008

答えて

0

android:fromYDelta=android:toYDelta=は終わりを意味viewself

  • に基づいて開始位置を意味しそう

    • あなたはあなたの1000msで

      でアニメーションが表示されますviewselfに基づく位置

    ビューを設定すると、android:layout_alignParentTop="true" 、ビューは上から中央にアニメーションされます。

    ビューを設定すると、android:layout_alignParentTop="true" 、ビューは中央から下にアニメートされます。