Hi I have stuck with the problem of creating a splash screen where the image is placed in center_vertical|center horizontal.how to translater over to center_horizontal|top in android.can any one please guide me how to do it.
-
Try this android:layout_gravity="top|center_horizontal" – Venkat May 08 '14 at 04:20
-
@Saravanan:how to translate to it – Giridharan May 08 '14 at 04:21
-
add this gravity="center_horizontal" properties to your parent layout which hold your image view. – Haresh Chhelana May 08 '14 at 04:27
-
Try this http://stackoverflow.com/questions/23465568/move-imageview-after-animation-update-position/23467534#23467534 – Rohit Goswami May 08 '14 at 05:00
2 Answers
Use animations to do this, for more information about animating views, you could refer to this link and also this
What you are actually looking for in translating a view from the center to the top of the screen, you could use translation animation using the xml.
1.Create a folder anim in the res folder 2.Add a resource file that describes your translation effect like :
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="50%p" android:fromYDelta="50%p"
android:toXDelta="50%p" android:toYDelta="0%p"
android:duration="1000"
android:fillAfter="true" />
You could experiment with the % values.
3.implement this in code like :
translateAnim= AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.translate_anim);
imageView.startAnimation(translateAnim);
Hope this much of clue suffices!
P.S: You could experiment with fillAfter
true or false, so that you could understand their effects better.

- 7,109
- 5
- 31
- 41
-
-
-
@Ratatouille:i am translating an image over top but after that image has to be fixed where it stops and login layout has been shown at center_vertical and canter_horizontal – Giridharan May 08 '14 at 04:38
-
do this, set the image to default center_horizontal, and top , then when the app starts via code start the animation of the view from the center of the screen and then when the animation stops it will remain at its default location when u set fillAfter to true (that is top), this is how generally the animations work – Rat-a-tat-a-tat Ratatouille May 08 '14 at 04:40
-
@Ratatoulli:but there is a slight deviation when it changes.. can u guide me in this.. – Giridharan May 08 '14 at 04:43
-
yeah, wait, m uploading the sample on github, you could look at it.. just a moment, [here](https://github.com/hearbeathorror/Animating-View-Translate) it is – Rat-a-tat-a-tat Ratatouille May 08 '14 at 04:50
-
@Rat-a-tat-a-tatRatatouille, please help me on this like in the link - https://stackoverflow.com/questions/62756897/android-smooth-animation-not-coming-fine – Naveen Jul 06 '20 at 17:36
This is I think best and easiest approach to achieve animation from center to top:
ivSplashCenter.animate()
.translationY(-((rlContainer.height - (ivSplashCenter.height * 2)) / 2).toFloat())
.setInterpolator(AccelerateInterpolator()).duration = 1500
Here, ivSplashCenter
is imageview and rlContainer
is my root view of XML
NOTE:
One thing you need to understand here is that I am keeping a space from the top edge of the height of the image by ivSplashCenter.height * 2
,
If you don't want any padding/space at the top then you can just use ivSplashCenter.height

- 13,761
- 4
- 85
- 82