简体   繁体   中英

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. it also implies the direction of translation. view1.getX() will get the current position.

If you don't want to use Translate class then you can update the position of the time at regular interval. 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. this should be be done in a thread because the UI thread may not be able to handle it effectively.

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