我使用Android 2.3手机和动画来移动imageView。 这是动画:
TranslateAnimation anim = new TranslateAnimation(0, xDest, yDest, yDest);
anim.setDuration(1000);
anim.setFillAfter(true);
MoveImagesOutsideOfScreen();
view.setVisibility(View.VISIBLE);
view.startAnimation(anim);
在动画之后,当我使用以下代码检测我的imageview上的触摸并移动它时,没有任何反应:
ImageView imageView=(ImageView)findViewById(R.id.imageSimple);
imageView.setOnTouchListener(new View.OnTouchListener()
{
PointF DownPT = new PointF(); // Record Mouse Position When Pressed Down
PointF StartPT = new PointF(); // Record Start Position of 'img'
@Override
public boolean onTouch(View v, MotionEvent event)
{
Log.w(TAG,"Touch started");
int eid = event.getAction();
switch (eid)
{
case MotionEvent.ACTION_MOVE:
PointF mv = new PointF(event.getX() - DownPT.x, event.getY() - DownPT.y);
v.setX((int) (StartPT.x + mv.x));
v.setY((int) (StartPT.y + mv.y));
StartPT = new PointF(v.getX(), v.getY());
Log.w(TAG,"Moved ");
break;
case MotionEvent.ACTION_DOWN:
DownPT.x = event.getX();
DownPT.y = event.getY();
StartPT = new PointF(v.getX(), v.getY());
break;
case MotionEvent.ACTION_UP:
// Nothing have to do
break;
default:
break;
}
return true;
}
});
我检查了日志,并且从未显示消息 Touch started 。是什么阻止了它?
更新:神圣@%*!似乎动画不会移动实际视图,而是移动某种副本(我没有看到它的概念,我认为创建副本是浪费的,大多数时候人们都想使用移动的对象)。
我在onCreate中保存了布局参数,当我将其设置回来时,我的视图是随机放置的。我应该怎样做才能让我的观点出现在动画中浪费双胞胎的地方?
paramsSimple= (RelativeLayout.LayoutParams) aq.id(R.id.imageSimple).getImageView().getLayoutParams();
paramsExpert= (RelativeLayout.LayoutParams) aq.id(R.id.imageExpert).getImageView().getLayoutParams();
public void onAnimationEnd(Animation animation)
{
view.setLayoutParams(view.getId()==R.id.imageSimple?paramsSimple:paramsExpert);