I'm trying to animate UI elements. I would like to move an editText and a Button from the middle to the top of the screen and display results of an http call below them in a table. It would be great if anyone could point me in the right direction, at this point I don't know wether I should use Java or XML for this.
Thanks in advance.
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 y-axis direction, as follows:
mAnimation = new TranslateAnimation(0, 0, 0, 599);
mAnimation.setDuration(10000);
mAnimation.setFillAfter(true);
mAnimation.setRepeatCount(-1);
mAnimation.setRepeatMode(Animation.REVERSE);
view.setAnimation(mAnimation);
Here view may be anything, textview, imageView etc.
accepted answer caused an error inside my code, code snippet below almost identical to accepted answer & worked without causing errors, to slide an object off the screen. i needed gestures tied to keyPad to also 'slide away' , and switched from TranslateAnimation to ObjectAnimator (second block of code below).
final LinearLayout keyPad = (LinearLayout)findViewById(R.id.keyPad);
moveKeyPadUp(keyPad);
private void moveKeyPadUp(LinearLayout keyPad){
Animation animation = new TranslateAnimation(0,0,0,-500);
animation.setDuration(1000);
animation.setFillAfter(true);
keyPad.startAnimation(animation);
}
private void moveKeyPadUpdated(LinearLayout keyPad){
ObjectAnimator mover = ObjectAnimator.ofFloat(keyPad,"translationY",0,-500);
mover.setDuration(300);
mover.start();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With