2012-02-29 2 views
0

위에서 아래로 곡선처럼 이미지를 움직이게하는 애니메이션을 만들려면 어떻게해야합니까? 여기에 TranslateAnimation을 사용했습니다. 하지만 x, y 좌표에 따라 위에서 아래로 이미지가 이동합니다. 그러나 커브처럼 이미지를 옮기고 싶습니다. 하지만 내 코드에서는 선처럼 움직입니다.TranslateAnimation이 android의 곡선과 같습니다.

public class ImageMoveActivity extends Activity { 
    /** Called when the activity is first created. */ 
    TranslateAnimation transform; 
    TextView tv; 
    ImageView im1,im2,im3; 

    @Override 

    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     transform = new TranslateAnimation(0, 150, 0, 300); 
     //transform = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 1, Animation.RELATIVE_TO_PARENT, 20, Animation.RELATIVE_TO_PARENT, 50, Animation.RELATIVE_TO_PARENT, 0); 
     //im1 = (ImageView)findViewById(R.id.imageView1); 
     im1 = (ImageView)findViewById(R.id.imageView1); 
     im2 = (ImageView)findViewById(R.id.imageView2); 
     im3 = (ImageView)findViewById(R.id.imageView3); 
     tv = (TextView)findViewById(R.id.Textview); 


     Bitmap bitmap = BitmapFactory.decodeResource(this 
       .getResources(), R.drawable.xxl); 
     /* set other image top of the first icon */ 
     Bitmap bitmapStar = BitmapFactory.decodeResource(this 
       .getResources(), R.drawable.icon); 

     Bitmap bmOverlay = Bitmap.createBitmap(bitmap.getWidth(), 
       bitmap.getHeight(), Config.ARGB_8888); 
//  Bitmap bmOverlay1 = Bitmap.createBitmap(bitmapStar.getWidth(), 
//    bitmapStar.getHeight(), Config.ARGB_8888); 
     Canvas canvas = new Canvas(bmOverlay); 
     //Canvas canvas1 = new Canvas(bmOverlay1); 
     canvas.drawARGB(0x00, 0, 0, 0); 
     canvas.drawBitmap(bitmap, 0, 0, null); 
     //canvas1.drawARGB(0x00, 0, 0, 0); 
     canvas.drawBitmap(bitmapStar, 0, 0, null); 

     BitmapDrawable dr = new BitmapDrawable(bmOverlay); 
     //BitmapDrawable dr1 = new BitmapDrawable(bmOverlay1); 
     dr.setBounds(10, 30, 10, 30); 
     //dr1.setBounds(10, 30, 10, 30); 

     im1.setImageDrawable(dr); 
     //im3.setImageDrawable(dr1); 

//im1.setImageDrawable(R.drawable.xxl); 
     im1.setOnClickListener(new OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       start(); 
       hide(); 
      } 
      private void start() { 
       // TODO Auto-generated method stub 
       im1.startAnimation(transform); 
       transform.setDuration(1000); 
       //transform.setFillAfter(true); 
      } 
      private void hide() { 
       // TODO Auto-generated method stub 
       im1.setVisibility(View.GONE); 
      } 

     }); 


    } 
} 

아무도 도와 드릴 수 있습니까?

답변

0

TranslateAnimation은 뷰를 한 지점에서 다른 지점으로 직선으로 이동할 수 있습니다. 내가 아는 한 당신은 다른 길을 제시 할 수 없습니다. 이를 위해 사용자 정의보기 및 캔버스를 사용하십시오. 여기서 도면을 그리거나 무효화하는 동안 x 및 y 좌표를 전달할 수 있습니다. View 클래스를 확장하는 동안 다음 메소드를 재정의해야합니다. 여기서 changeCoordinate() 메서드는 커브의 x, y 좌표를 변경할 수 있습니다.

public void onDraw(Canvas canvas){ 
    canvas.drawBitmap(bitmap,x,y,null); 
    changeCoordinate(); 
    invalidate() 
} 
0

커브에서 한 지점에서 다른 지점으로 애니메이션을 변환하고 뷰에 애니메이션을 적용 할 수 있습니다.

우리는 애니메이트 될 이미지 뷰 및 A1 및 A2가 있다면 적용될 애니메이션처럼 :

imgView.clearAnimation(); 
    imgView.startAnimation(a1); 

    imgView.clearAnimation(); 
    imgView.startAnimation(a2);