简体   繁体   English

Android从视图翻译动画

[英]Android translate animation from view

How can I implement appearance one view from another? 如何实现一个视图与另一个视图的外观?
在此处输入图片说明

To use the translate animation class 使用翻译动画类

View view1 = (View)findViewById(R.id.view_id);

     //defining an animation to scroll the view and the direction
        TranslateAnimation mAnimation = new TranslateAnimation(view1.getX(),180,0,0);
      // time it will take to finish reach destination, this means how fast the view will translate
        mAnimation.setDuration(1000); 
       // repetition 
        mAnimation.setRepeatMode(Animation.RESTART);
        mAnimation.setRepeatCount(Animation.ABSOLUTE);
        view.setAnimation(mAnimation);

the TranslateAnimation(value1, value2, value3, value4) indicate the starting co-ordinate and the ending co-ordinate of the view. TranslateAnimation(value1, value2, value3, value4)指示TranslateAnimation(value1, value2, value3, value4)的开始坐标和结束坐标。 it also implies the direction of translation. 它还暗示了翻译的方向。 view1.getX() will get the current position. view1.getX()将获取当前位置。

If you don't want to use Translate class then you can update the position of the time at regular interval. 如果您不想使用Translate类,则可以定期更新时间位置。 probably every one-sec. 大概每隔一秒钟。 you can use this code 您可以使用此代码

View view = new View(this);
    while(true){
        sleep(1000);
        view.setX(view.getX() + 1);

        // define a condition to stop;

    }

The view.getX() will return the current position of the view then increase it by a value at regular interval(1 sec), each time the line execute it get the current location and increase it. view.getX()将返回视图的当前位置,然后以规则的间隔(1秒)将其增加一个值,每次执行该行时,它都会获取当前位置并增加该位置。 this should be be done in a thread because the UI thread may not be able to handle it effectively. 这应该在线程中完成,因为UI线程可能无法有效处理它。

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

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