【发布时间】:2014-10-03 03:59:42
【问题描述】:
我面临接下来的两个问题:
1) 当我将图像视图从屏幕外部转换到屏幕内部时,当图像移动时,图像被裁剪,当完成移动时,图像视图修复并显示正常。为什么会这样?
2) 我使用 translateAnimation 将图像视图从 (0,0) 移动到 (300,0)。 我已经实现了 on touch 监听器。当我尝试移动之前翻译的图像视图时,当我尝试用手指移动时,ontouch 不起作用,但如果用手指触摸位置 (0,0),图像视图移动但图像不显示!我不明白发生了什么。 我尝试用手指在位置 (300,0) 移动 imageView 但不起作用,当我触摸位置 (0,0) 时移动。但是,如果我在 x 轴上移动例如 100,则图像视图不在位置(100,0),它在(400,0)!我不明白发生了什么。缺少某些东西,我认为图像视图保存了开始移动或某些东西的位置,我不明白。如果我将翻译动画删除到该图像视图,ontouch 工作正常!
我希望我是清楚的。
这是我的问题 1 的代码:
public void showImageFromOutside(ImageView image){
image.setImageResource(obtenerImagen(cartasJugador.get(0).toString()));
TranslateAnimation animation1 = new TranslateAnimation(100, 425, 100, 525);
animation1.setDuration(800);
animation1.setFillAfter(true);
animation1.setAnimationListener(animationListener);
image.startAnimation(animation1);
}
这是我的问题 2 的代码:
public void moveImageView(Imageview image){
animation = new TranslateAnimation(0, 300, 0, 0);
animation.setDuration(250);
animation.setFillAfter(true);
animation.setAnimationListener(animationListener);
image.startAnimation(animation);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
seMueve = true;
break;
case MotionEvent.ACTION_MOVE:
if (seMueve) {
x = (int) event.getRawX() - v.getWidth()/2;
y = (int) event.getRawY() - v.getHeight();
v.setX(x);
v.setY(y);
}
break;
case MotionEvent.ACTION_UP:
seMueve = false;
break;
}
v.performClick();
return seMueve;
}
问候
【问题讨论】:
标签: android imageview translate-animation