简体   繁体   中英

How to move a drawable across the screen

I have been looking around for an answer to this and have not been finding much. I hope this is not hard to answer. What I want to do is have a drawable or an image move left to right or vise versa across my main menu screen. For example, if I had a picture of a cloud is there a way to have it start off the screen and move from left to right across it and the loop back to the beginning. The picture of the cloud would stay the same and it would just move across the screen. Thanks for any help you can give me.

Use Translation framework to achieve this, this works as:

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

So you need to write your code for moving view in x-axis direction, as follows:

 mAnimation = new TranslateAnimation(0, 599, 0, 0);
    mAnimation.setDuration(10000);
    mAnimation.setFillAfter(true);
    mAnimation.setRepeatCount(-1);
    mAnimation.setRepeatMode(Animation.REVERSE);
    view.setAnimation(mAnimation);

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