Reputation: 975
I have a button in (0,0) position when i click on that it should be moved to (-x,-y) position for ex (-0,-2) position OR (x,-y) position for ex (0,-2) position.How to implement this logic.
Upvotes: 2
Views: 177
Reputation: 1321
try this:
float fromX=0;
float toX=0;
float fromY=40;
float toY=40;
TranslateAnimation animation = new TranslateAnimation(fromX, toX, fromY, toY);
animation.setDuration(300);
animation.setFillAfter(true);
yourView.startAnimation(animation);
Upvotes: 2
Reputation: 168
If u use Android 3.0+
ObjectAnimator animation = ObjectAnimator.ofFloat(yourButton, "x", newX);
animation.setDuration(animTime); //In milliseconds
animation.start();
if u dont use Android 3.0+ u cant use the library: http://nineoldandroids.com/ to backport this funcionality.
cheers
Upvotes: 1
Reputation: 2883
you can use translate animation for that
Animation animation= AnimationUtils.loadAnimation( this, R.anim.animation);
button.startAnimation( animation);
create amin folder in res and in amin folder create xml named as animation.xml
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:fromXDelta="0"
android:fromYDelta="0"
android:toXDelta="-60"
android:toYDelta="-30" />
</set>
now you can play with translation
Upvotes: 2