roro
roro

Reputation: 127

Android TranslateAnimation - Moving an image from the right side of the screen into the screen

I am desperate right now and I really really need some help. I want an image to move in from the right of the screen into it.

Initially, the image exists outside the screen area. However, based on an event, I want it to slide in.

Does anyone know how this can be done? I read in a tutorial(http://developerlife.com/tutorials/?p=343) online that if "the animation effects extend beyond the screen region then they are clipped outside those boundaries".

Hence, according to this tutorial, this is not possible. However, remember the android 2.2 lock screens? The two images (for unlocking and putting it on silence) used to slide in from left and right side of the screen respectively.

I can make my image slide in from the left side of the screen but not from the right. Any ideas on how I can get this done???

If you want to see my code, I can put it up.

Upvotes: 0

Views: 1746

Answers (2)

Hints
Hints

Reputation: 1

You can use the following code: TranslateAnimation animation = new TranslateAnimation(-970.0f, 2000.0f, 0.0f, 0.0f); ImageView.startAnimation(animation);

The 1st two parameters are for from which position to which position you want the image to move horizontally. I am using Nexus 9 tab. Here the image is moving from outside the screen moves to the right end.

Upvotes: 0

zienkikk
zienkikk

Reputation: 2414

This is actually pretty simple. In your layout, position the ImageView to where you want it at the end of the animation and either set its visibility to INVISIBLE or GONE, depending on your layout needs. Then when the event occurs, start a TranslateAnimation with starting coordinates set using RELATIVE_TO_PARENT with the x of 1.0 (all the way to the right) and the destination x coordinates of 0.0 with type RELATIVE_TO_SELF so that your image end up in the position determined by the layout. Make sure to also turn on the visibility as you start the animation.

PS. It's important that whatever ViewGroup your ImageView is nested under extends all the way to the right of the screen. Otherwise the ImageView will be clipped against its parent's bounds.

Upvotes: 3

Related Questions