2017-09-03 2 views
0

이미지가 있습니다. 왼쪽 아래 구석에 작은 각도로 회전해야합니다. 이 애니메이션은 화면을 탭할 때 작동합니다. 이미지가 나타나서 회전합니다. 그러나 다른 위치에 대해서는 피벗이 일정합니다. 어떻게 프로그래밍 방식으로 피벗을 동적으로 설정할 수 있습니까?회전 애니메이션의 동적 피벗을 설정하는 방법

?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shareInterpolator="false"> 
    <rotate 
     android:duration="500" 
     android:interpolator="@android:anim/linear_interpolator" 
     android:pivotY="100%" 
     android:pivotX="0%" 
     android:repeatCount="0" 
     android:toDegrees="10"/> 
</set> 

우리가 값을 우리 getX()getY()로 피벗 값을 줄 수있는 방법이 있습니까?

+0

로테이션 애니메이션은 어떻게하고 있습니까? 그렇게하기 위해 무엇을 사용하고 있느냐에 따라 다른 대답을 얻을 수 있습니다. 행렬로 작업하는 경우 회전 행렬을 적용하기 전에 원점을 피벗 점으로 변환 할 수 있습니다. –

+0

매트릭스 사용을 시도하지 않았습니다. 이제 내가 할거야. 나는 회전을하기 위해 xml을 사용했다. –

답변

0

답을 얻었다. 이 일을 통해 해냈습니다

var screenH=Resources.getSystem().getDisplayMetrics().heightPixels 
var screenH=Resources.getSystem().getDisplayMetrics().widthPixels 

var x= ("x value of your pivot)/screenW 

var y= ("y value of your pivot)/screenH 

var rotateAnim=RotateAnimation(0.0f , 20.0f , Animation.RELATIVE_TO_PARENT , x , 
Animation.RELATIVE_TO_PARENT , y) 

rotateAnim.setDuration(1000) 
rotateAnim.setFillAfter(true) 

view.startAnimation(rotateAnim) 
관련 문제