简体   繁体   中英

Android Translation animation

i am trying to animate an image view by ensuring that the object appears in the center of the screen and then translates up.. to its final position. the code i used is as follows.

<set xmlns:android="http://schemas.android.com/apk/res/android">  
<translate 
      android:fromXDelta="0"
      android:fromYDelta="400"
      android:toYDelta="0"
      android:duration="800"/>
</set>

This code works when u have a device of 4.7"(galaxy s3) screen size the image will appear at the center of the screen and then move to its set position. But on a screen of 4" (S advance or htc desire x) the image practically appears at the screen bottom.

So is there any way to ensure that the image is at the center of the screen heedless of the device on which the code is running?? Thanks in advance..

Use percentages instead of values to make the Animation uniform across all screen sizes.

  • The animation should apply its transformation after it ends

    android:fillAfter="true"

  • The animation begins from the vertical center, ie 50% of Y

    android:fromYDelta="50%p"

  • The animation ends at the top, ie 0% of Y

    android:toYDelta="0%p"

XML:

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

    <translate
        android:duration="800"
        android:fillAfter="true"
        android:fromYDelta="50%p"
        android:toYDelta="0%p" />

</set>

thanks for ur response..

i tried ur suggestion 's and i found that using 50%p to then in a 4 inch screen the image view is present at around 3\\4of the screen. but when i use 25%p then its around the center. in case of s advance its center and in s3 its relatively center.. i guess it depends on the size of the image.(dimention)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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