私の回転がどのように見えるかは次のとおりです。タッチリスナーを使用してその中心についてのアンドロイドのレイアウトビューを回転
私がダウンして、アクションのために耳を傾け、回転の角度を計算しようとすると、回転アイコンの上に移動するとのEditTextをカプセル化するレイアウト全体への回転の角度を適用しています。適用される回転は、相対レイアウトをカプセル化するほぼ中心でなければなりません。
ここでは、これを達成するための方法をtouchListener rotationアイコンに示します。
if(v == ivRotateSticker){
//TODO grab xc and yc using (top and bottom)/2 and (left and right)/2 to grab center of sticker after each rotation
final float x = event.getX();
final float y = event.getY();
rlTextStickerLayout.getGlobalVisibleRect(myViewRect);
xc = myViewRect.width()/2;
yc = myViewRect.height()/2;
dx = scaleReceiver.getWidth() - myViewRect.width();
dy = scaleReceiver.getHeight() - myViewRect.height();
leftBound = scaleReceiver.getX();
topBound = scaleReceiver.getY();
switch (event.getAction()){
case MotionEvent.ACTION_DOWN:
mViewAngle = rlTextStickerLayout.getRotation();
mPrevAngle = Math.toDegrees(Math.atan2(x - xc, yc - y));
break;
case MotionEvent.ACTION_MOVE:
Log.d("EventRegistered", " " + event.getRawX() + "--" + dx + " -- " + dy);
mCurrAngle = Math.toDegrees(Math.atan2(x - xc, yc - y));
if (x >= leftBound && y >= topBound && x <= dx && y <= dy) {
float rot = (float) (mViewAngle + mCurrAngle - mPrevAngle);
rlTextStickerLayout.setRotation((float) (mViewAngle + mCurrAngle - mPrevAngle));
Log.d("stickerRotation"," "+rot);
}
break;
}
return true;
}
しかし、結果の回転はきらきらしく、必要に応じて滑らかではありません。また、ステッカーを別の場所に移動すると、新しい中心をどのように更新するのですか?ステッカーを動かした後の回転が回転中心を劇的に変更します。どうすればより滑らかな回転を達成できますか?