2012-05-17 3 views
2

내 응용 프로그램에서 이미지 용 애니메이션을 만들었습니다. 이미지는 화면 가운데 왼쪽부터 시작됩니다. 이제 이미지가 왼쪽 상단 모서리에있는 모든 장치의 올바른 위치에 배치되도록해야합니다. 현재 장치의 왼쪽 상단 구석에 다른 위치에 배치됩니다. 어떻게 해결할 수 있습니까? 내 코드는 다음과 같습니다.Android에서 올바른 위치로 애니메이션 번역

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:interpolator="@android:anim/linear_interpolator" 
    android:fillAfter="true"> 
    <translate 
     android:fromXDelta="0%p" 
     android:toXDelta="-36%p" 
     android:fromYDelta="0%p" 
     android:toYDelta="-30.9%p" 
     android:duration="500" 
     android:fillAfter="true" /> 
</set> 

아무도 도와 줄 수 있습니까?

답변

0

나는 이것으로 꽤 좋은 결과를 얻었으므로 이것이 당신이나 어느 누구에게 도움이되기를 바랍니다. 아이디어는 간단합니다. 이 XML를 통해 최종 위치를 무엇 당신이 에 애니메이션을 적용 할

위치는 내가 TranslateAnimation를 사용하고 0으로 값에 값에서 모든 float 값으로 및 을 그 을 설정합니다. 이런 방식으로 위젯/뷰가 움직이며 xml에 배치 된 위치에 놓이게됩니다.

TextView을 화면 외부에서 xml에 지정된 위치로 애니메이션화하는 작은 예제입니다. 여기

//This is just for getting the from value, from where animation starts. 
WindowManager wm = (WindowManager) mContext 
     .getSystemService(Context.WINDOW_SERVICE); 
Display display = wm.getDefaultDisplay(); 
int width = display.getWidth(); 

Animation moveRighttoLeft = new TranslateAnimation(width, 0, 0, 0); 
moveRighttoLeft.setDuration(700); 

AnimationSet animation = new AnimationSet(false); 
animation.addAnimation(moveRighttoLeft); 
myTextView.setAnimation(animation); 

가있는 XML의

<TextView 
    android:id="@+id/mytextview" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="This is a Text View" 
    android:layout_marginLeft="30dp"/> 
관련 문제