2010-06-29 2 views
35

다음을 작성하여 화면 중앙에 아이콘을 회전시키고 대신 왼쪽 상단 모서리 (즉, ImageView의 원점 x = 0, y = 0)를 중심으로 회전합니다. ImageView 또는 RotateAnimation의 일부 속성을 설정하는 것이 간단해야하지만, 알아낼 수는 없습니다.안드로이드 아이콘을 중심점으로 돌리는 방법은 무엇입니까?

public class IconPromoActivity extends Activity { 
    private static final float ROTATE_FROM = 0.0f; 
    private static final float ROTATE_TO = -10.0f * 360.0f;// 3.141592654f * 32.0f; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     ImageView favicon = (ImageView) findViewById(R.id.favicon); 

     RotateAnimation r; // = new RotateAnimation(ROTATE_FROM, ROTATE_TO); 
     r = new RotateAnimation(ROTATE_FROM, ROTATE_TO, 0, 0, 40, 0); 
     r.setDuration((long) 2*1500); 
     r.setRepeatCount(0); 
     favicon.startAnimation(r); 
    } 
} 

답변

74

시도 : r = new RotateAnimation(ROTATE_FROM, ROTATE_TO, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);

+1

당신이 이것을 설명 할 수 있습니다. 그래서 우리의 필요에 따라 쉽게 수정할 수 있습니다. – Nepster

+0

그게 내가 찾고있는거야. – tounaobun

4

이 나를 위해 작동합니다

img = (ImageView)findViewById(R.id.ImageView01); 
RotateAnimation rotateAnimation = new RotateAnimation(30, 90, 
    Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 
+0

어떻게 멈추라 고 말할 때까지 계속 회전하도록 이미지에이를 추가할까요? – Zapnologica

+0

'rotationAnimation.setDuration (Animation.INFINITE)' 하고 애니메이션을 중지 할 때 '이미지 뷰 myRotatingImage = (이미지 뷰) mRoot.findViewById (R.id.my_rotating_image)' 'myRotatingImage.clearAnimation() ; –

+3

그것은 작동하지 않습니다 : java.lang.IllegalArgumentException : 애니메이션 기간은 음수가 될 수 없습니다 –

관련 문제