简体   繁体   English

Android翻译动画

[英]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. 当您的设备屏幕尺寸为4.7“(galaxy s3)时,此代码将起作用,图像将出现在屏幕中央,然后移至其设置位置。但是在4”屏幕上(S前进或htc期望x)该图像实际上出现在屏幕底部。

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" 机器人:fillAfter = “真”

  • The animation begins from the vertical center, ie 50% of Y 动画从垂直中心开始,即Y的50%

    android:fromYDelta="50%p" 机器人:fromYDelta = “50%P”

  • The animation ends at the top, ie 0% of Y 动画在顶部结束,即Y的0%

    android:toYDelta="0%p" 机器人:toYDelta = “0%P”

XML: 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. 我尝试了我们的建议,然后发现在4英寸的屏幕上使用50%p图像时,图像视图位于屏幕的3 \\ 4左右。 but when i use 25%p then its around the center. 但是,当我使用25%p时,它在中心附近。 in case of s advance its center and in s3 its relatively center.. i guess it depends on the size of the image.(dimention) 在s推进其中心而在s3推进其相对中心的情况..我想这取决于图像的大小。(尺寸)

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

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