翻译动画纠正Android的位置 [英] Translate animation to correct position in Android

查看:113
本文介绍了翻译动画纠正Android的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序创建一个图像动画。图像开始从中间到屏幕的左上角的到来。现在,我需要确保该图像获得放置在所有设备正确的位置是在左上角。
目前它被放置在不同的设备的不同位置处的左上角。我该如何解决?
我有我的code如下:

I have created an animation for an image in my application. The image starts coming from the middle till the top left corner of screen. Now I need to make sure that the image get placed at the right position in all the devices which is at the top left corner. Currently it gets placed at different positions for different devices at the top left corner. How can I fix it ? I have my code as follows :

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator"
    android:fillAfter="true">
    <translate
        android:fromXDelta="0%p"
        android:toXDelta="-36%p"
        android:fromYDelta="0%p"
        android:toYDelta="-30.9%p"
        android:duration="500"
        android:fillAfter="true" />
</set>

任何人都可以请帮助。

Can anyone please help.

推荐答案

我得到了这个有些pretty好成绩,所以希望这可以帮助你和任何一个。这个想法很简单。

I got some pretty good results with this, so hope this helps you or any one. The idea is simple.

位置要设置动画什么的这是通过XML的最终位置,然后我用 TranslateAnimation 和值设置它的 任何浮点值和将值 0 。通过这种方式,窗口小部件/视图和动画来在你已经在XML中定位它的地方休息。

Position what you want to animate to it's final position via xml then I use TranslateAnimation and set its from values to any float values and to values as 0. In this way the widget/view animates and comes to rest in the place where you have positioned it in xml.

一个小例子来一个动画的TextView 从屏幕到XML中指定的位置之外。

A small example to animate a TextView from outside the screen to its position specified in xml.

//This is just for getting the from value, from where animation starts.
WindowManager wm = (WindowManager) mContext
        .getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
int width = display.getWidth();

Animation  moveRighttoLeft = new TranslateAnimation(width, 0, 0, 0);
moveRighttoLeft.setDuration(700);

AnimationSet animation = new AnimationSet(false);
animation.addAnimation(moveRighttoLeft);
myTextView.setAnimation(animation);

下面是XML的

<TextView
    android:id="@+id/mytextview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="This is a Text View"
    android:layout_marginLeft="30dp"/>

这篇关于翻译动画纠正Android的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆