动画上下左右判断
老师的动画上下左右判断错了?Toast的结果和实际的不一致
public void changeDataByImageView(final ImageView mImageView) {
// 创建动画,设置方向、移动距离
TranslateAnimation translateAnimation = null;
if (mImageView.getX() > iv_null_ImageView.getX()) {// 在空方块下面
// 往上移动
translateAnimation = new TranslateAnimation(0.1f, -mImageView.getWidth(), 0.1f, 0.1f);
Toast.makeText(MainActivity.this, "上移", Toast.LENGTH_SHORT).show();
} else if (mImageView.getX() < iv_null_ImageView.getX()) {//
// 下
translateAnimation = new TranslateAnimation(0.1f, mImageView.getWidth(), 0.1f, 0.1f);
Toast.makeText(MainActivity.this, "下移", Toast.LENGTH_SHORT).show();
} else if (mImageView.getY() > iv_null_ImageView.getY()) {//
// 左
translateAnimation = new TranslateAnimation(0.1f, 0.1f, 0.1f, -mImageView.getWidth());
Toast.makeText(MainActivity.this, "左移", Toast.LENGTH_SHORT).show();
} else if (mImageView.getY() < iv_null_ImageView.getY()) {//
// 右
translateAnimation = new TranslateAnimation(0.1f, 0.1f, 0.1f, mImageView.getWidth());
Toast.makeText(MainActivity.this, "右移", Toast.LENGTH_SHORT).show();
}
// 设置动画时长
translateAnimation.setDuration(70);
// 动画结束之后停留
translateAnimation.setFillAfter(true);
// 动画结束后真正的把数据交换
translateAnima