private void moveViewToScreenCenter(final ImageView img, int x) {
DisplayMetrics dm = new DisplayMetrics();
this.getWindowManager().getDefaultDisplay().getMetrics(dm);
img.animate()
.translationX(0)
.withEndAction(new Runnable() {
@Override
public void run() {
enableAll();
showDialog();
}
})
.translationY(-x * dm.heightPixels / 6)
.setDuration(2000)
.setInterpolator(new LinearInterpolator())
.setStartDelay(0);
}
public void showDialog()
{
final CharSequence[] items = {"0", "1", "2","3","4","5"};
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setTitle("which floor is your destination");
alertDialogBuilder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
if (items[item].equals("0")) {
moveViewToScreen(img, 0);
} else if (items[item].equals("1")) {
moveViewToScreen(img, 1);
} else if (items[item].equals("2")) {
moveViewToScreen(img, 2);
} else if (items[item].equals("3")) {
moveViewToScreen(img, 3);
} else if (items[item].equals("4")) {
moveViewToScreen(img,4);
}else if (items[item].equals("5")) {
moveViewToScreen(img,5);
}
dialog.dismiss();
}
});
alertDialogBuilder.show();
}
private void moveViewToScreen(final ImageView img, int x) {
DisplayMetrics dm = new DisplayMetrics();
this.getWindowManager().getDefaultDisplay().getMetrics(dm);
img.animate()
.translationX(0)
.withEndAction(new Runnable() {
@Override
public void run() {
enableAll();
}
})
.translationY(-x * dm.heightPixels / 6)
.setDuration(2000)
.setInterpolator(new LinearInterpolator())
.setStartDelay(0);
}
Buttons are disabled (disableALL()) during animation but animation seems fast between far floors and slow between consecutive ones . i'm still new to android and simple animation stuff like this