2013-11-26 4 views
1

번역 애니메이션을 통해 이미지 단추를 다른 위치 (다른 이미지 단추 위치)로 변환하려고합니다. 나는 둘 다 지위가있다. 애니메이션 방법은 모두 상대 위치 변경을 사용하지만 절대 변환에 ​​관심이 있습니다. Android에서 그렇게 할 수있는 방법이 있습니까?애니메이션이 제대로 작동하지 않습니까?

public void startAnimationFindChant(View view) { 
      int[] locationSource = new int[2]; 
      int[] locationDestination = new int[2]; 
      view.geLocationOnScreen(locationSource); 
      Log.d("locationSource",locationSource[0]+" "+locationSource[1]); 
      ImageButton findachant1 = (ImageButton) findViewById(R.id.findachanticon1); 

      findachant1.getLocationOnScreen(locationDestination); 
      Log.d("locationDestination",locationDestination[0]+" "+locationDestination[1]); 

      TranslateAnimation animation = new TranslateAnimation(
        Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0, 
        Animation.ABSOLUTE, locationSource[1], Animation.ABSOLUTE, 
        locationDestination[1]); 
      animation.setFillAfter(true); 
      view.startAnimation(animation); 
     } 

답변

0
public void doSlideUp(View view) { 
    LinearLayout myView = (LinearLayout) findViewById(R.id.content_area); 
    Animation slideUp = setLayoutAnim_slideup(); 
    myView.startAnimation(slideUp); 

} 

public void doSlideDown(View view) { 
    RelativeLayout myView = (RelativeLayout) findViewById(R.id.content_area1); 
    Animation slideDown = setLayoutAnim_slidedown(); 
    myView.startAnimation(slideDown); 
} 

public Animation setLayoutAnim_slidedown() { 

    AnimationSet set = new AnimationSet(true); 

    Animation animation = new TranslateAnimation(
      Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 
      0.0f, Animation.RELATIVE_TO_SELF, -1.0f, 
      Animation.RELATIVE_TO_SELF, 0.0f); 
    animation.setDuration(2000); 
    animation.setAnimationListener(new AnimationListener() { 

     @Override 
     public void onAnimationStart(Animation animation) { 
     } 

     @Override 
     public void onAnimationRepeat(Animation animation) { 
     } 

     @Override 
     public void onAnimationEnd(Animation animation) { 

     } 
    }); 
    set.addAnimation(animation); 

    LayoutAnimationController controller = new LayoutAnimationController(
      set, 0.25f); 

    return animation; 
} 

public Animation setLayoutAnim_slideup() { 

    AnimationSet set = new AnimationSet(true); 

    Animation animation = new TranslateAnimation(
      Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 
      0.0f, Animation.RELATIVE_TO_SELF, 0.0f, 
      Animation.RELATIVE_TO_SELF, -1.0f); 
    animation.setDuration(2000); 
    animation.setAnimationListener(new AnimationListener() { 
     @Override 
     public void onAnimationStart(Animation animation) { 

     } 

     @Override 
     public void onAnimationRepeat(Animation animation) { 

     } 

     @Override 
     public void onAnimationEnd(Animation animation) { 




     } 
    }); 
    set.addAnimation(animation); 
    LayoutAnimationController controller = new LayoutAnimationController(
      set, 0.25f); 
    return animation; 
} 

이 시도하고 필요에 따라 Y 축에 애니메이션 ASIX X의 값을 변화.

+0

나는 OP가 두 위치 사이의 절대적인 변환에 관해 물었을 것으로 추측한다. – noob

+0

예 두 위치간에 절대 변환이 필요합니다. 도와주세요. 나를 위해 –

+0

가 작동하지 않습니다 –

0

I는 ObjectAnimator을 사용하여 두 위치 사이 TranslateAnimation 대한 간단한 클래스를 만들었다 -

private void translateAnimateView(View source, View target, 
     AnimatorListener listener) { 
    ObjectAnimator animator = ObjectAnimator.ofFloat(source, 
      "translationY", 0, target.getTop() - source.getTop()); 
    animator.addListener(listener); 

    animator.setDuration(1000); 
    animator.start(); 
} 

이 방법 된 threee 인수, 소스보기 타겟 조회 및 청취자 (널이 될 수있다) 받아 들인다. 소스가 대상보기에 도달하도록 애니메이션으로 표시됩니다. 나는 Y 변환만을 추가했지만 실제로 x 번역도 포함 할 수 있습니다.

이렇게하면 절대 위치를 사용하여 번역 할 수 있습니다. 당신은 어쨌든 비록 대신 뷰의 상단 좌표를 사용할 수 있습니다.

관련 문제