onTouch 이벤트를 사용하지만 이미지 뷰를 다시 게시 한 후에 지속적으로 회전하는 이미지 뷰를 이동하려고합니다. 대신 자신의 축을 중심으로 회전하지 않고 긴 원형 경로를 중심으로 회전합니다. 지금까지 내가 roatate 수 있어요onTouch를 사용하여 지속적으로 회전하는 이미지 뷰 안드로이드 이동하기 MotionEvent.ACTION_MOVE
을 : 나는 onTouch 이벤트를 사용하여 위치를 변경 한 후 얻고 무엇
이된다
내가 원하는 아래 그림과 같이이다 다음 코드를 사용하여 자체 축을 기준으로 이미지를 만듭니다.
RotateAnimation rotateanimation = new RotateAnimation(0, 360,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
필자는 알아낼 수없는 pivotPoints와 관련이 있다고 생각합니다. 아래는 코드입니다.
final ImageView iv = findViewById(R.id.imageView);
final RotateAnimation rotateAnimation;
RotateAnimation rotateanimation = new RotateAnimation(0, 360,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
rotateanimation.setDuration(7000);
rotateanimation.setInterpolator(new LinearInterpolator());
rotateanimation.setRepeatCount(Animation.INFINITE);
rotateanimation.setFillAfter(true);
iv.startAnimation(rotateanimation);
iv.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, final MotionEvent event)
{
switch (event.getAction())
{
case MotionEvent.ACTION_MOVE :
PointF mv = new PointF(event.getX() - DownPT.x -1, event.getY() - DownPT.y -1);
iv.setX((int)(StartPT.x+mv.x));
iv.setY((int)(StartPT.y+mv.y));
iv.setPivotX(StartPT.x+mv.x);
iv.setPivotY(StartPT.y+mv.y);
//something to do here i guess
rotateanimation = new RotateAnimation(0, 360,
Animation.RELATIVE_TO_SELF, iv.getPivotX(),
Animation.RELATIVE_TO_SELF, iv.getPivotY());
iv.startAnimation(rotateanimation);
/**************************************************************/
StartPT = new PointF(iv.getX(), iv.getY());
break;
case MotionEvent.ACTION_DOWN :
int centerXOnImage= iv.getWidth()/2;
int centerYOnImage= iv.getHeight()/2;
DownPT.x =centerXOnImage;
DownPT.y =centerYOnImage;
StartPT = new PointF(iv.getX(), iv.getY());
break;
case MotionEvent.ACTION_UP :
// Nothing have to do
break;
default :
break;
}
return true;
}
});
의견이 있으십니까 ??