如何TranslateAnimation工作的机器人? [英] How does TranslateAnimation works android?

查看:219
本文介绍了如何TranslateAnimation工作的机器人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过

TranslateAnimation (float fromXDelta, float toXDelta, float fromYDelta, float toYDelta)

但仍然感到困惑如何翻译动画

任何一个,请解释一下我如何工作的阅读文档这话说

any one please explain how it works i read docs which saying

fromXDelta  Change in X coordinate to apply at the start of the animation
toXDelta    Change in X coordinate to apply at the end of the animation
fromYDelta  Change in Y coordinate to apply at the start of the animation
toYDelta    Change in Y coordinate to apply at the end of the animation 

但还是它不是我清楚如何将其工作。

but still its not clear to me how its working.

修改:我有一个按钮的LinearLayout 无任何子女在当我点击按钮我要生成一个动态的TextView 和动画制作的的TextView 的LinearLayout 数量 TextViews 将取决于点击上的按钮数量。

EDIT: I have a Button and a LinearLayout without any child in that when i am clicking on the Button i want to generate a dynamic TextView and animate that TextView to the LinearLayout the number of TextViews will depend upon the number of click on the Button.

推荐答案

AFAIK,就不会有这之间的相对连接。

AFAIK,there would be relative connection between this.

也就是说,如果你想翻译从一个隐藏的TextView 屏幕向左屏幕,在点击一个按钮的右边,你实际上需要从100%的X方向(转换屏幕右侧)与X方向(屏幕左侧的0%)。

That is,if you want to translate a hidden textview from right of screen to left of screen,on click of a button,you actually need to translate it from 100% of X-direction(right side of screen) to 0% of X-direction(left side of screen).

在这一点上,你并不需要在all.so这将是0%,同时为options.So终于改变Y方向,你将有:

At this point,you don't need to change Y-direction at all.so that would be 0% for both the options.So finally,you will have:

fromXDelta 100%

toXDelta 0%

fromYDelta 0%

toYDelta 0%

您可以通过设置在0这一比例为100,按您的要求限制视图组件的。

you can restrict view of the component by setting this percentages between 0 to 100,as per your requirement.

同样,如果您需要翻译你的Y方向分量,以及,那么你需要改变0%为其他值。

Similarly,if you need to translate your component on Y-direction as well,then you need to change 0% to some other value.

希望,其清晰的给你了。

Hope,its clear to you now.

编辑:

你的要求,你需要重写的onclick按钮1,在那里你可以控制按钮2的知名度,以及翻译。

for your requirement,you need to override onclick of button-1,and there you can control button-2's visibility as well as translation.

在你的资源创建动画文件夹动画文件。

create animation file in anim folder in your res.

translate_button.xml:

<?xml version="1.0" encoding="utf-8"?>
<!-- translating button from right to left -->
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false">
    <translate
        android:fromXDelta="100%" android:toXDelta="0%"
        android:fromYDelta="0%" android:toYDelta="0%"
        android:duration="900"
    />
</set>

现在,在您的活动文件,

now,in your activity file,

...

// ll  is linear layout containing button_2
//counter is used to manage visibility of button_2 on click of button_1,i.e.1st click-button_2 would be visible,on 2nd click on button_1,it would be invisible.

//you can change behavior as per your need

button_2.setVisibility(View.GONE);
button_1.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View arg0) {

        if(counter<1)
        {
            counter++;                  
            button_2.setVisibility(View.VISIBLE);
            Animation anim=AnimationUtils.loadAnimation(context, R.anim.translate_button);
            button_2.startAnimation(anim);
        }
        else
        {
            counter=0;
            button_2.setVisibility(View.GONE);
        }
    }
});
ll.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View arg0) {

        if(counter==1)
        {
            counter=0;
            button_2.setVisibility(View.GONE);
        }
    }
});

...

这篇关于如何TranslateAnimation工作的机器人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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