I’m kinda new to building apps on Android. I do have some Java developing experience, but the project I do now is first on Android.
I’m building a basic cards game, and I want the card to move to the specific location I touch.
I did it, and the card moves to the touch point, but once the animation is over it bounces back to starting position.
I added a Image re-position code, but now it begins the animation from that point.
any ideas, anyone?
the code I did is:
public class FinallyActivity extends Activity {
/** Called when the activity is first created. */
EditText DBG;
ImageView iv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
DBG = (EditText) findViewById(R.id.editText1);
iv = (ImageView) findViewById(R.id.imV1);
}
private void RunAnimations(MotionEvent event) {
// Animation b = AnimationUtils.loadAnimation(this,R.anim.cardtrans);
int xStart, yStart, dx, dy;
xStart = iv.getLeft();
yStart = iv.getTop();
Animation b = new TranslateAnimation(Animation.ABSOLUTE,0,Animation.ABSOLUTE,event.getX()-50,
Animation.ABSOLUTE,0,Animation.ABSOLUTE,event.getY()- 105);
b.setDuration(3000);
iv.clearAnimation();
iv.startAnimation(b);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
RunAnimations(event);
}
iv.layout((int)event.getX()-25,(int) event.getY()-105,
(int)event.getX()+25,(int) event.getY()-35);
return true;
}
}
Thanks All!!
b.fillAfter(true)
http://developer.android.com/reference/android/view/animation/Animation.html#setFillAfter(boolean)